plac-micro-common 1.1.9 → 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/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
18
|
__exportStar(require("./decorators"), exports);
|
|
19
|
-
__exportStar(require("./modules"), exports);
|
|
20
19
|
__exportStar(require("./guards"), exports);
|
|
20
|
+
__exportStar(require("./modules"), exports);
|
|
21
|
+
__exportStar(require("./pipes"), exports);
|
|
21
22
|
__exportStar(require("./services"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError, ValidationPipe } from "@nestjs/common";
|
|
2
|
+
export type PlacValidationErrorBody = {
|
|
3
|
+
code: "VALIDATION_ERROR";
|
|
4
|
+
message: string;
|
|
5
|
+
errors: Record<string, string[]>;
|
|
6
|
+
};
|
|
7
|
+
export declare function flattenValidationErrors(validationErrors?: ValidationError[]): Record<string, string[]>;
|
|
8
|
+
export declare function createGlobalValidationPipe(): ValidationPipe;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flattenValidationErrors = flattenValidationErrors;
|
|
4
|
+
exports.createGlobalValidationPipe = createGlobalValidationPipe;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
function flattenValidationErrors(validationErrors = []) {
|
|
7
|
+
const errors = {};
|
|
8
|
+
const walk = (err, parentPath = "") => {
|
|
9
|
+
const path = parentPath ? `${parentPath}.${err.property}` : err.property;
|
|
10
|
+
if (err.constraints) {
|
|
11
|
+
errors[path] ?? (errors[path] = []);
|
|
12
|
+
errors[path].push(...Object.values(err.constraints));
|
|
13
|
+
}
|
|
14
|
+
if (err.children?.length) {
|
|
15
|
+
for (const child of err.children)
|
|
16
|
+
walk(child, path);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
for (const err of validationErrors)
|
|
20
|
+
walk(err);
|
|
21
|
+
return errors;
|
|
22
|
+
}
|
|
23
|
+
function createGlobalValidationPipe() {
|
|
24
|
+
return new common_1.ValidationPipe({
|
|
25
|
+
whitelist: true,
|
|
26
|
+
skipMissingProperties: false,
|
|
27
|
+
transform: true,
|
|
28
|
+
transformOptions: { enableImplicitConversion: true },
|
|
29
|
+
exceptionFactory: (validationErrors = []) => {
|
|
30
|
+
const errors = flattenValidationErrors(validationErrors);
|
|
31
|
+
// IMPORTANT: don't add trace_id/success here — let your exception filter do it globally.
|
|
32
|
+
const body = {
|
|
33
|
+
code: "VALIDATION_ERROR",
|
|
34
|
+
message: "Request validation failed",
|
|
35
|
+
errors,
|
|
36
|
+
};
|
|
37
|
+
return new common_1.BadRequestException(body);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./global_validation.pipe";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./global_validation.pipe"), exports);
|