anote-server-libs 0.4.4 → 0.4.6
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/package.json +1 -1
- package/services/WithBody.js +5 -10
- package/services/WithBody.ts +2 -7
package/package.json
CHANGED
package/services/WithBody.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WithBody = void 0;
|
|
3
|
+
exports.WithBody = exports.ajv = void 0;
|
|
4
4
|
const ajv_1 = require("ajv");
|
|
5
|
-
|
|
6
|
-
ajv.addKeyword({
|
|
5
|
+
exports.ajv = new ajv_1.default();
|
|
6
|
+
exports.ajv.addKeyword({
|
|
7
7
|
keyword: 'maxDigits',
|
|
8
8
|
type: 'number',
|
|
9
9
|
schemaType: 'number',
|
|
10
|
-
|
|
11
|
-
const { data, schema } = cxt;
|
|
12
|
-
const op = (0, ajv_1._) `!==`;
|
|
13
|
-
const roundedData = Math.round(data * 10 ** schema) / (10 ** schema);
|
|
14
|
-
cxt.fail((0, ajv_1._) `${roundedData} ${op} ${data}`);
|
|
15
|
-
}
|
|
10
|
+
validate: (schema, data) => typeof data === 'number' && Math.round(data * 10 ** schema) / (10 ** schema) === data
|
|
16
11
|
});
|
|
17
12
|
function WithBody(schema) {
|
|
18
13
|
if (schema.type === 'object') {
|
|
@@ -28,7 +23,7 @@ function WithBody(schema) {
|
|
|
28
23
|
});
|
|
29
24
|
schema.required = required;
|
|
30
25
|
}
|
|
31
|
-
const validate = ajv.compile(schema);
|
|
26
|
+
const validate = exports.ajv.compile(schema);
|
|
32
27
|
return function (_, __, descriptor) {
|
|
33
28
|
if (typeof descriptor.value === 'function') {
|
|
34
29
|
const previousMethod = descriptor.value;
|
package/services/WithBody.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import {Request, Response} from 'express';
|
|
2
2
|
import Ajv, {_} from 'ajv';
|
|
3
3
|
|
|
4
|
-
const ajv = new Ajv();
|
|
4
|
+
export const ajv = new Ajv();
|
|
5
5
|
ajv.addKeyword({
|
|
6
6
|
keyword: 'maxDigits',
|
|
7
7
|
type: 'number',
|
|
8
8
|
schemaType: 'number',
|
|
9
|
-
|
|
10
|
-
const {data, schema} = cxt;
|
|
11
|
-
const op = _`!==`;
|
|
12
|
-
const roundedData = Math.round(data * 10 ** schema) / (10 ** schema);
|
|
13
|
-
cxt.fail(_`${roundedData} ${op} ${data}`);
|
|
14
|
-
}
|
|
9
|
+
validate: (schema: number, data: any) => typeof data === 'number' && Math.round(data * 10 ** schema) / (10 ** schema) === data
|
|
15
10
|
});
|
|
16
11
|
|
|
17
12
|
export function WithBody(schema: any) {
|