@donmahallem/turbo-validate-request 0.3.8 → 0.3.13

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/cjs/index.js CHANGED
@@ -9,49 +9,49 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
9
9
 
10
10
  const Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
11
11
 
12
- /*
13
- * Package @donmahallem/turbo-validate-request
14
- * Source https://donmahallem.github.io/js-libs/
15
- */
16
- const convertValidationError = (error) => {
17
- const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
18
- switch (error.keyword) {
19
- case 'required':
20
- return new turbo.RequestError(`Missing property ${error.params.missingProperty} at '${errorPath}'`, 400);
21
- case 'pattern':
22
- return new turbo.RequestError(`Value doesn't match pattern at: '${errorPath}'`, 400);
23
- case 'type':
24
- return new turbo.RequestError(`Invalid type at '${errorPath}'. Expected ${error.params.type}`, 400);
25
- default:
26
- return new turbo.RequestError(`Invalid '${errorPath}'`, 400);
27
- }
12
+ /*
13
+ * Package @donmahallem/turbo-validate-request
14
+ * Source https://donmahallem.github.io/js-libs/
15
+ */
16
+ const convertValidationError = (error) => {
17
+ const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
18
+ switch (error.keyword) {
19
+ case 'required':
20
+ return new turbo.RequestError(`Missing property ${error.params.missingProperty} at '${errorPath}'`, 400);
21
+ case 'pattern':
22
+ return new turbo.RequestError(`Value doesn't match pattern at: '${errorPath}'`, 400);
23
+ case 'type':
24
+ return new turbo.RequestError(`Invalid type at '${errorPath}'. Expected ${error.params.type}`, 400);
25
+ default:
26
+ return new turbo.RequestError(`Invalid '${errorPath}'`, 400);
27
+ }
28
28
  };
29
29
 
30
- /*
31
- * Package @donmahallem/turbo-validate-request
32
- * Source https://donmahallem.github.io/js-libs/
33
- */
34
- /**
35
- * Checks a request against the given schema
36
- *
37
- * @param {string} key property of the request to check the schema against
38
- * @param {JSONSchemaType} schema the jsonschema
39
- * @param {Ajv} ajvInstance optional ajv to be used
40
- * @returns {RequestHandler} express middleware
41
- */
42
- const validateRequest = (key, schema, ajvInstance = new Ajv__default["default"]()) => {
43
- const validateFunction = ajvInstance.compile(schema);
44
- return (req, res, next) => {
45
- if (!validateFunction(req[key])) {
46
- const errors = validateFunction.errors;
47
- next(convertValidationError(errors[0]));
48
- return;
49
- }
50
- next();
51
- };
30
+ /*
31
+ * Package @donmahallem/turbo-validate-request
32
+ * Source https://donmahallem.github.io/js-libs/
33
+ */
34
+ /**
35
+ * Checks a request against the given schema
36
+ *
37
+ * @param {string} key property of the request to check the schema against
38
+ * @param {JSONSchemaType} schema the jsonschema
39
+ * @param {Ajv} ajvInstance optional ajv to be used
40
+ * @returns {RequestHandler} express middleware
41
+ */
42
+ const validateRequest = (key, schema, ajvInstance = new Ajv__default["default"]()) => {
43
+ const validateFunction = ajvInstance.compile(schema);
44
+ return (req, res, next) => {
45
+ if (!validateFunction(req[key])) {
46
+ const errors = validateFunction.errors;
47
+ next(convertValidationError(errors[0]));
48
+ return;
49
+ }
50
+ next();
51
+ };
52
52
  };
53
53
 
54
54
  exports.validateRequest = validateRequest;
55
- // BUILD: Sun Feb 06 2022 11:28:34 GMT+0100 (Central European Standard Time)
55
+ // BUILD: Wed Mar 02 2022 11:08:45 GMT+0000 (Coordinated Universal Time)
56
56
 
57
57
  //# sourceMappingURL=index.js.map
package/dist/esm/index.js CHANGED
@@ -1,49 +1,49 @@
1
1
  import Ajv from 'ajv';
2
2
  import { RequestError } from '@donmahallem/turbo';
3
3
 
4
- /*
5
- * Package @donmahallem/turbo-validate-request
6
- * Source https://donmahallem.github.io/js-libs/
7
- */
8
- const convertValidationError = (error) => {
9
- const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
10
- switch (error.keyword) {
11
- case 'required':
12
- return new RequestError(`Missing property ${error.params.missingProperty} at '${errorPath}'`, 400);
13
- case 'pattern':
14
- return new RequestError(`Value doesn't match pattern at: '${errorPath}'`, 400);
15
- case 'type':
16
- return new RequestError(`Invalid type at '${errorPath}'. Expected ${error.params.type}`, 400);
17
- default:
18
- return new RequestError(`Invalid '${errorPath}'`, 400);
19
- }
4
+ /*
5
+ * Package @donmahallem/turbo-validate-request
6
+ * Source https://donmahallem.github.io/js-libs/
7
+ */
8
+ const convertValidationError = (error) => {
9
+ const errorPath = error.instancePath === '' ? 'root' : error.instancePath;
10
+ switch (error.keyword) {
11
+ case 'required':
12
+ return new RequestError(`Missing property ${error.params.missingProperty} at '${errorPath}'`, 400);
13
+ case 'pattern':
14
+ return new RequestError(`Value doesn't match pattern at: '${errorPath}'`, 400);
15
+ case 'type':
16
+ return new RequestError(`Invalid type at '${errorPath}'. Expected ${error.params.type}`, 400);
17
+ default:
18
+ return new RequestError(`Invalid '${errorPath}'`, 400);
19
+ }
20
20
  };
21
21
 
22
- /*
23
- * Package @donmahallem/turbo-validate-request
24
- * Source https://donmahallem.github.io/js-libs/
25
- */
26
- /**
27
- * Checks a request against the given schema
28
- *
29
- * @param {string} key property of the request to check the schema against
30
- * @param {JSONSchemaType} schema the jsonschema
31
- * @param {Ajv} ajvInstance optional ajv to be used
32
- * @returns {RequestHandler} express middleware
33
- */
34
- const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
35
- const validateFunction = ajvInstance.compile(schema);
36
- return (req, res, next) => {
37
- if (!validateFunction(req[key])) {
38
- const errors = validateFunction.errors;
39
- next(convertValidationError(errors[0]));
40
- return;
41
- }
42
- next();
43
- };
22
+ /*
23
+ * Package @donmahallem/turbo-validate-request
24
+ * Source https://donmahallem.github.io/js-libs/
25
+ */
26
+ /**
27
+ * Checks a request against the given schema
28
+ *
29
+ * @param {string} key property of the request to check the schema against
30
+ * @param {JSONSchemaType} schema the jsonschema
31
+ * @param {Ajv} ajvInstance optional ajv to be used
32
+ * @returns {RequestHandler} express middleware
33
+ */
34
+ const validateRequest = (key, schema, ajvInstance = new Ajv()) => {
35
+ const validateFunction = ajvInstance.compile(schema);
36
+ return (req, res, next) => {
37
+ if (!validateFunction(req[key])) {
38
+ const errors = validateFunction.errors;
39
+ next(convertValidationError(errors[0]));
40
+ return;
41
+ }
42
+ next();
43
+ };
44
44
  };
45
45
 
46
46
  export { validateRequest };
47
- // BUILD: Sun Feb 06 2022 11:28:34 GMT+0100 (Central European Standard Time)
47
+ // BUILD: Wed Mar 02 2022 11:08:45 GMT+0000 (Coordinated Universal Time)
48
48
 
49
49
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { RequestError } from '@donmahallem/turbo';
2
- import { DefinedError } from 'ajv';
3
- export declare const convertValidationError: (error: DefinedError) => RequestError;
1
+ import { RequestError } from '@donmahallem/turbo';
2
+ import { DefinedError } from 'ajv';
3
+ export declare const convertValidationError: (error: DefinedError) => RequestError;
4
4
  //# sourceMappingURL=convert-validation-error.d.ts.map
@@ -1,2 +1,2 @@
1
- import 'mocha';
1
+ import 'mocha';
2
2
  //# sourceMappingURL=convert-validation-error.spec.d.ts.map
@@ -1,2 +1,2 @@
1
- export { validateRequest } from './validate-request';
1
+ export { validateRequest } from './validate-request';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,15 +1,15 @@
1
- import Ajv, { JSONSchemaType } from 'ajv';
2
- import { RequestHandler } from 'express';
3
- declare type CheckKeys = 'query' | 'params' | 'body';
4
- declare type MethodSignature = <T = object>(key: CheckKeys, schema: JSONSchemaType<T>, ajvInstance?: Ajv) => RequestHandler;
5
- /**
6
- * Checks a request against the given schema
7
- *
8
- * @param {string} key property of the request to check the schema against
9
- * @param {JSONSchemaType} schema the jsonschema
10
- * @param {Ajv} ajvInstance optional ajv to be used
11
- * @returns {RequestHandler} express middleware
12
- */
13
- export declare const validateRequest: MethodSignature;
14
- export {};
1
+ import Ajv, { JSONSchemaType } from 'ajv';
2
+ import { RequestHandler } from 'express';
3
+ declare type CheckKeys = 'query' | 'params' | 'body';
4
+ declare type MethodSignature = <T = object>(key: CheckKeys, schema: JSONSchemaType<T>, ajvInstance?: Ajv) => RequestHandler;
5
+ /**
6
+ * Checks a request against the given schema
7
+ *
8
+ * @param {string} key property of the request to check the schema against
9
+ * @param {JSONSchemaType} schema the jsonschema
10
+ * @param {Ajv} ajvInstance optional ajv to be used
11
+ * @returns {RequestHandler} express middleware
12
+ */
13
+ export declare const validateRequest: MethodSignature;
14
+ export {};
15
15
  //# sourceMappingURL=validate-request.d.ts.map
@@ -1,2 +1,2 @@
1
- import 'mocha';
1
+ import 'mocha';
2
2
  //# sourceMappingURL=validate-request.spec.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donmahallem/turbo-validate-request",
3
- "version": "0.3.8",
3
+ "version": "0.3.13",
4
4
  "description": "Turbo Helpers for express.js",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -53,7 +53,7 @@
53
53
  "@types/express": "4.17.13",
54
54
  "@types/supertest": "2.0.11",
55
55
  "ajv": "8.10.0",
56
- "express": "4.17.2",
56
+ "express": "4.17.3",
57
57
  "supertest": "6.2.2"
58
58
  },
59
59
  "peerDependencies": {
@@ -61,7 +61,7 @@
61
61
  "express": "^4.17.1"
62
62
  },
63
63
  "dependencies": {
64
- "@donmahallem/turbo": "^2.3.8"
64
+ "@donmahallem/turbo": "^2.3.10"
65
65
  },
66
- "gitHead": "412e9dbe12ed9e22062db814fa3a4297cb3f6c12"
66
+ "gitHead": "09c100740084394a02013773cd554110661c4501"
67
67
  }