@naturalcycles/backend-lib 9.18.0 → 9.19.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/validation/ajv/ajvValidateRequest.js +2 -5
- package/dist/validation/joi/joiValidateRequest.js +2 -5
- package/dist/validation/validateRequest.util.d.ts +2 -3
- package/dist/validation/zod/zodValidateRequest.js +2 -5
- package/package.json +2 -2
- package/src/validation/ajv/ajvValidateRequest.ts +2 -5
- package/src/validation/joi/joiValidateRequest.ts +2 -5
- package/src/validation/validateRequest.util.ts +2 -3
- package/src/validation/zod/zodValidateRequest.ts +2 -5
|
@@ -19,13 +19,10 @@ class AjvValidateRequest {
|
|
|
19
19
|
* Keep in mind that this will also remove all values that are not in the schema.
|
|
20
20
|
*/
|
|
21
21
|
headers(req, schema, opt = {}) {
|
|
22
|
-
return this.validate(req, 'headers', schema,
|
|
23
|
-
mutate: false,
|
|
24
|
-
...opt,
|
|
25
|
-
});
|
|
22
|
+
return this.validate(req, 'headers', schema, opt);
|
|
26
23
|
}
|
|
27
24
|
validate(req, reqProperty, schema, opt = {}) {
|
|
28
|
-
const { mutate
|
|
25
|
+
const { mutate } = opt;
|
|
29
26
|
const originalProperty = req[reqProperty] || {};
|
|
30
27
|
const item = mutate ? originalProperty : { ...originalProperty };
|
|
31
28
|
// Ajv mutates the input
|
|
@@ -20,13 +20,10 @@ class ValidateRequest {
|
|
|
20
20
|
* Keep in mind that this will also remove all values that are not in the schema.
|
|
21
21
|
*/
|
|
22
22
|
headers(req, schema, opt = {}) {
|
|
23
|
-
return this.validate(req, 'headers', schema,
|
|
24
|
-
mutate: false,
|
|
25
|
-
...opt,
|
|
26
|
-
});
|
|
23
|
+
return this.validate(req, 'headers', schema, opt);
|
|
27
24
|
}
|
|
28
25
|
validate(req, reqProperty, schema, opt = {}) {
|
|
29
|
-
const { mutate
|
|
26
|
+
const { mutate } = opt;
|
|
30
27
|
const originalProperty = req[reqProperty] || {};
|
|
31
28
|
// Joi does not mutate the input
|
|
32
29
|
const { error, value } = getValidationResult(originalProperty, schema, `request ${reqProperty}`);
|
|
@@ -12,10 +12,9 @@ export interface ReqValidationOptions<ERR extends AppError> {
|
|
|
12
12
|
*/
|
|
13
13
|
report?: boolean | ((err: ERR) => boolean);
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Defaults to false.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* Exception is `headers` validation, where the default is `false`.
|
|
17
|
+
* When set to true, the validated object will be replaced with the converted value.
|
|
19
18
|
*
|
|
20
19
|
* To avoid mutation - shallow copy is performed.
|
|
21
20
|
*/
|
|
@@ -20,13 +20,10 @@ class ZodValidateRequest {
|
|
|
20
20
|
* Keep in mind that this will also remove all values that are not in the schema.
|
|
21
21
|
*/
|
|
22
22
|
headers(req, schema, opt = {}) {
|
|
23
|
-
return this.validate(req, 'headers', schema,
|
|
24
|
-
mutate: false,
|
|
25
|
-
...opt,
|
|
26
|
-
});
|
|
23
|
+
return this.validate(req, 'headers', schema, opt);
|
|
27
24
|
}
|
|
28
25
|
validate(req, reqProperty, schema, opt = {}) {
|
|
29
|
-
const { mutate
|
|
26
|
+
const { mutate } = opt;
|
|
30
27
|
const originalProperty = req[reqProperty] || {};
|
|
31
28
|
// Zod does not mutate the input
|
|
32
29
|
const { error, data } = zSafeValidate(originalProperty, schema);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.19.0",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@sentry/node": "^9"
|
|
7
7
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@sentry/node": "^9",
|
|
30
30
|
"@types/ejs": "^3",
|
|
31
31
|
"fastify": "^5",
|
|
32
|
-
"@naturalcycles/dev-lib": "
|
|
32
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
33
33
|
},
|
|
34
34
|
"exports": {
|
|
35
35
|
".": "./dist/index.js",
|
|
@@ -41,10 +41,7 @@ class AjvValidateRequest {
|
|
|
41
41
|
schema: AjvSchema<T>,
|
|
42
42
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
43
43
|
): T {
|
|
44
|
-
return this.validate(req, 'headers', schema,
|
|
45
|
-
mutate: false,
|
|
46
|
-
...opt,
|
|
47
|
-
})
|
|
44
|
+
return this.validate(req, 'headers', schema, opt)
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
private validate<T>(
|
|
@@ -53,7 +50,7 @@ class AjvValidateRequest {
|
|
|
53
50
|
schema: AjvSchema<T>,
|
|
54
51
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
55
52
|
): T {
|
|
56
|
-
const { mutate
|
|
53
|
+
const { mutate } = opt
|
|
57
54
|
const originalProperty = req[reqProperty] || {}
|
|
58
55
|
const item: T = mutate ? originalProperty : { ...originalProperty }
|
|
59
56
|
|
|
@@ -42,10 +42,7 @@ class ValidateRequest {
|
|
|
42
42
|
schema: AnySchema<T>,
|
|
43
43
|
opt: ReqValidationOptions<JoiValidationError> = {},
|
|
44
44
|
): T {
|
|
45
|
-
return this.validate(req, 'headers', schema,
|
|
46
|
-
mutate: false,
|
|
47
|
-
...opt,
|
|
48
|
-
})
|
|
45
|
+
return this.validate(req, 'headers', schema, opt)
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
private validate<T>(
|
|
@@ -54,7 +51,7 @@ class ValidateRequest {
|
|
|
54
51
|
schema: AnySchema<T>,
|
|
55
52
|
opt: ReqValidationOptions<JoiValidationError> = {},
|
|
56
53
|
): T {
|
|
57
|
-
const { mutate
|
|
54
|
+
const { mutate } = opt
|
|
58
55
|
const originalProperty = req[reqProperty] || {}
|
|
59
56
|
|
|
60
57
|
// Joi does not mutate the input
|
|
@@ -54,10 +54,9 @@ export interface ReqValidationOptions<ERR extends AppError> {
|
|
|
54
54
|
report?: boolean | ((err: ERR) => boolean)
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Defaults to false.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
* Exception is `headers` validation, where the default is `false`.
|
|
59
|
+
* When set to true, the validated object will be replaced with the converted value.
|
|
61
60
|
*
|
|
62
61
|
* To avoid mutation - shallow copy is performed.
|
|
63
62
|
*/
|
|
@@ -41,10 +41,7 @@ class ZodValidateRequest {
|
|
|
41
41
|
schema: ZodType<T>,
|
|
42
42
|
opt: ReqValidationOptions<ZodValidationError> = {},
|
|
43
43
|
): T {
|
|
44
|
-
return this.validate(req, 'headers', schema,
|
|
45
|
-
mutate: false,
|
|
46
|
-
...opt,
|
|
47
|
-
})
|
|
44
|
+
return this.validate(req, 'headers', schema, opt)
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
private validate<T>(
|
|
@@ -53,7 +50,7 @@ class ZodValidateRequest {
|
|
|
53
50
|
schema: ZodType<T>,
|
|
54
51
|
opt: ReqValidationOptions<ZodValidationError> = {},
|
|
55
52
|
): T {
|
|
56
|
-
const { mutate
|
|
53
|
+
const { mutate } = opt
|
|
57
54
|
const originalProperty = req[reqProperty] || {}
|
|
58
55
|
|
|
59
56
|
// Zod does not mutate the input
|