@donmahallem/turbo-validate-request 3.1.1 → 3.2.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/{esm/convert-validation-error.mjs → convert-validation-error.js} +3 -6
- package/dist/convert-validation-error.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/validate-request.mjs → validate-request.js} +4 -7
- package/dist/validate-request.js.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/convert-validation-error.cjs +0 -24
- package/dist/cjs/convert-validation-error.cjs.map +0 -1
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/validate-request.cjs +0 -30
- package/dist/cjs/validate-request.cjs.map +0 -1
- package/dist/esm/convert-validation-error.mjs.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/validate-request.mjs.map +0 -1
- /package/dist/{types/convert-validation-error.d.ts → convert-validation-error.d.ts} +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
- /package/dist/{types/validate-request.d.ts → validate-request.d.ts} +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { RequestError } from '@donmahallem/turbo';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Package @donmahallem/turbo-validate-request
|
|
5
3
|
* Source https://donmahallem.github.io/turbo/
|
|
6
4
|
*/
|
|
7
|
-
|
|
5
|
+
import { RequestError } from '@donmahallem/turbo';
|
|
6
|
+
export const convertValidationError = (error) => {
|
|
8
7
|
const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
|
|
9
8
|
switch (error.keyword) {
|
|
10
9
|
case 'required':
|
|
@@ -17,6 +16,4 @@ const convertValidationError = (error) => {
|
|
|
17
16
|
return new RequestError(`Invalid '${errorPath}'`, 400);
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
|
-
|
|
21
|
-
export { convertValidationError };
|
|
22
|
-
//# sourceMappingURL=convert-validation-error.mjs.map
|
|
19
|
+
//# sourceMappingURL=convert-validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-validation-error.js","sourceRoot":"","sources":["../src/convert-validation-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,CAAC,MAAM,sBAAsB,GAA0C,CAAC,KAAmB,EAAgB,EAAE;IAC/G,MAAM,SAAS,GAAW,KAAK,CAAC,YAAY,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;IAClF,QAAQ,KAAK,CAAC,OAAO,EAAE,CAAC;QACpB,KAAK,UAAU;YACX,OAAO,IAAI,YAAY,CAAC,oBAAoB,KAAK,CAAC,MAAM,CAAC,eAAe,QAAQ,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC;QACvG,KAAK,SAAS;YACV,OAAO,IAAI,YAAY,CAAC,oCAAoC,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC;QACnF,KAAK,MAAM;YACP,OAAO,IAAI,YAAY,CAAC,oBAAoB,SAAS,eAAe,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;QAClG;YACI,OAAO,IAAI,YAAY,CAAC,YAAY,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/D,CAAC;AACL,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
import { convertValidationError } from './convert-validation-error.mjs';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Package @donmahallem/turbo-validate-request
|
|
6
3
|
* Source https://donmahallem.github.io/turbo/
|
|
7
4
|
*/
|
|
5
|
+
import Ajv from 'ajv';
|
|
6
|
+
import { convertValidationError } from './convert-validation-error.js';
|
|
8
7
|
/**
|
|
9
8
|
* Checks a request against the given schema
|
|
10
9
|
* @param {string} key property of the request to check the schema against
|
|
@@ -12,7 +11,7 @@ import { convertValidationError } from './convert-validation-error.mjs';
|
|
|
12
11
|
* @param {Ajv} ajvInstance optional ajv to be used
|
|
13
12
|
* @returns {RequestHandler} express middleware
|
|
14
13
|
*/
|
|
15
|
-
const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
|
|
14
|
+
export const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
|
|
16
15
|
const validateFunction = ajvInstance.compile(schema);
|
|
17
16
|
return (req, res, next) => {
|
|
18
17
|
if (!validateFunction(req[key])) {
|
|
@@ -23,6 +22,4 @@ const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
|
|
|
23
22
|
next();
|
|
24
23
|
};
|
|
25
24
|
};
|
|
26
|
-
|
|
27
|
-
export { validateRequest };
|
|
28
|
-
//# sourceMappingURL=validate-request.mjs.map
|
|
25
|
+
//# sourceMappingURL=validate-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request.js","sourceRoot":"","sources":["../src/validate-request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,GAAuD,MAAM,KAAK,CAAC;AAE1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAIvE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoB,CAC5C,GAAc,EACd,MAAyB,EACzB,cAAmB,IAAI,GAAG,EAAE,EACd,EAAE;IAChB,MAAM,gBAAgB,GAAqB,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;QAC7D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAmB,gBAAgB,CAAC,MAAwB,CAAC;YACzE,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,OAAO;QACX,CAAC;QACD,IAAI,EAAE,CAAC;IACX,CAAC,CAAC;AACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donmahallem/turbo-validate-request",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Turbo Helpers for express.js",
|
|
5
|
-
"types": "./dist/
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
6
|
"private": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"default": "./dist/cjs/index.cjs"
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"express",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"typedocMain": "./src/index.ts",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "tsc -p tsconfig.lib.json",
|
|
20
20
|
"build:readme": "npx @appnest/readme generate --input ../package_readme_blueprint.md --config readme_config.json",
|
|
21
21
|
"test": "mocha --config ../../.mocharc.json",
|
|
22
22
|
"test:coverage": "c8 --config ../../.nycrc.json npm run test",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"express": "^5.0.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@donmahallem/turbo": "^3.
|
|
68
|
+
"@donmahallem/turbo": "^3.2.0"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "2c43089a7426bcc2600993f36442dc868edb9b83"
|
|
71
71
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const turbo = require('@donmahallem/turbo');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Package @donmahallem/turbo-validate-request
|
|
7
|
-
* Source https://donmahallem.github.io/turbo/
|
|
8
|
-
*/
|
|
9
|
-
const convertValidationError = (error) => {
|
|
10
|
-
const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
|
|
11
|
-
switch (error.keyword) {
|
|
12
|
-
case 'required':
|
|
13
|
-
return new turbo.RequestError(`Missing property ${error.params.missingProperty} at '${errorPath}'`, 400);
|
|
14
|
-
case 'pattern':
|
|
15
|
-
return new turbo.RequestError(`Value doesn't match pattern at: '${errorPath}'`, 400);
|
|
16
|
-
case 'type':
|
|
17
|
-
return new turbo.RequestError(`Invalid type at '${errorPath}'. Expected ${error.params.type}`, 400);
|
|
18
|
-
default:
|
|
19
|
-
return new turbo.RequestError(`Invalid '${errorPath}'`, 400);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.convertValidationError = convertValidationError;
|
|
24
|
-
//# sourceMappingURL=convert-validation-error.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convert-validation-error.cjs","sources":["../../src/convert-validation-error.ts"],"sourcesContent":[null],"names":["RequestError"],"mappings":";;;;AAAA;;;AAGG;AAKU,MAAA,sBAAsB,GAA0C,CAAC,KAAmB,KAAkB;AAC/G,IAAA,MAAM,SAAS,GAAW,KAAK,CAAC,YAAY,KAAK,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,YAAY;AACjF,IAAA,QAAQ,KAAK,CAAC,OAAO;AACjB,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,IAAIA,kBAAY,CAAC,CAAA,iBAAA,EAAoB,KAAK,CAAC,MAAM,CAAC,eAAe,QAAQ,SAAS,CAAA,CAAA,CAAG,EAAE,GAAG,CAAC;AACtG,QAAA,KAAK,SAAS;YACV,OAAO,IAAIA,kBAAY,CAAC,CAAA,iCAAA,EAAoC,SAAS,CAAG,CAAA,CAAA,EAAE,GAAG,CAAC;AAClF,QAAA,KAAK,MAAM;AACP,YAAA,OAAO,IAAIA,kBAAY,CAAC,CAAA,iBAAA,EAAoB,SAAS,CAAe,YAAA,EAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA,CAAE,EAAE,GAAG,CAAC;AACjG,QAAA;YACI,OAAO,IAAIA,kBAAY,CAAC,CAAA,SAAA,EAAY,SAAS,CAAG,CAAA,CAAA,EAAE,GAAG,CAAC;;AAElE;;;;"}
|
package/dist/cjs/index.cjs
DELETED
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Ajv = require('ajv');
|
|
4
|
-
const convertValidationError = require('./convert-validation-error.cjs');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Package @donmahallem/turbo-validate-request
|
|
8
|
-
* Source https://donmahallem.github.io/turbo/
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Checks a request against the given schema
|
|
12
|
-
* @param {string} key property of the request to check the schema against
|
|
13
|
-
* @param {JSONSchemaType} schema the jsonschema
|
|
14
|
-
* @param {Ajv} ajvInstance optional ajv to be used
|
|
15
|
-
* @returns {RequestHandler} express middleware
|
|
16
|
-
*/
|
|
17
|
-
const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
|
|
18
|
-
const validateFunction = ajvInstance.compile(schema);
|
|
19
|
-
return (req, res, next) => {
|
|
20
|
-
if (!validateFunction(req[key])) {
|
|
21
|
-
const errors = validateFunction.errors;
|
|
22
|
-
next(convertValidationError.convertValidationError(errors[0]));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
next();
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
exports.validateRequest = validateRequest;
|
|
30
|
-
//# sourceMappingURL=validate-request.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-request.cjs","sources":["../../src/validate-request.ts"],"sourcesContent":[null],"names":["convertValidationError"],"mappings":";;;;;AAAA;;;AAGG;AAQH;;;;;;AAMG;AACI,MAAM,eAAe,GAAoB,CAC5C,GAAc,EACd,MAAyB,EACzB,WAAmB,GAAA,IAAI,GAAG,EAAE,KACZ;IAChB,MAAM,gBAAgB,GAAqB,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AACtE,IAAA,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,KAAU;QAC7D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;AAC7B,YAAA,MAAM,MAAM,GAAmB,gBAAgB,CAAC,MAAwB;YACxE,IAAI,CAACA,6CAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC;;AAEJ,QAAA,IAAI,EAAE;AACV,KAAC;AACL;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convert-validation-error.mjs","sources":["../../src/convert-validation-error.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAKU,MAAA,sBAAsB,GAA0C,CAAC,KAAmB,KAAkB;AAC/G,IAAA,MAAM,SAAS,GAAW,KAAK,CAAC,YAAY,KAAK,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,YAAY;AACjF,IAAA,QAAQ,KAAK,CAAC,OAAO;AACjB,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,IAAI,YAAY,CAAC,CAAA,iBAAA,EAAoB,KAAK,CAAC,MAAM,CAAC,eAAe,QAAQ,SAAS,CAAA,CAAA,CAAG,EAAE,GAAG,CAAC;AACtG,QAAA,KAAK,SAAS;YACV,OAAO,IAAI,YAAY,CAAC,CAAA,iCAAA,EAAoC,SAAS,CAAG,CAAA,CAAA,EAAE,GAAG,CAAC;AAClF,QAAA,KAAK,MAAM;AACP,YAAA,OAAO,IAAI,YAAY,CAAC,CAAA,iBAAA,EAAoB,SAAS,CAAe,YAAA,EAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA,CAAE,EAAE,GAAG,CAAC;AACjG,QAAA;YACI,OAAO,IAAI,YAAY,CAAC,CAAA,SAAA,EAAY,SAAS,CAAG,CAAA,CAAA,EAAE,GAAG,CAAC;;AAElE;;;;"}
|
package/dist/esm/index.mjs
DELETED
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-request.mjs","sources":["../../src/validate-request.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;AAGG;AAQH;;;;;;AAMG;AACI,MAAM,eAAe,GAAoB,CAC5C,GAAc,EACd,MAAyB,EACzB,WAAmB,GAAA,IAAI,GAAG,EAAE,KACZ;IAChB,MAAM,gBAAgB,GAAqB,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AACtE,IAAA,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,KAAU;QAC7D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;AAC7B,YAAA,MAAM,MAAM,GAAmB,gBAAgB,CAAC,MAAwB;YACxE,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC;;AAEJ,QAAA,IAAI,EAAE;AACV,KAAC;AACL;;;;"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|