@middy/validator 3.0.0-alpha.1 → 3.0.0-alpha.5

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +6 -10
  3. package/package.json +6 -5
package/README.md CHANGED
@@ -62,7 +62,7 @@ NOTES:
62
62
  - At least one of `inputSchema` or `outputSchema` is required.
63
63
  - **Important** Compiling schemas on the fly will cause a 50-100ms performance hit during cold start for simple JSON Schemas. Precompiling is highly recommended.
64
64
  - Default ajv plugins used: `ajv-i18n`, `ajv-formats`, `ajv-formats-draft2019`
65
- - If you'd like to have the error details as part of the response, it will need to be handled separately. You can access them from `request.error.details`, the original response can be found at `request.error.response`.
65
+ - If you'd like to have the error details as part of the response, it will need to be handled separately. You can access them from `request.error.cause`, the original response can be found at `request.error.response`.
66
66
 
67
67
  ## Sample usage
68
68
 
package/index.js CHANGED
@@ -39,17 +39,14 @@ const validatorMiddleware = (opts = {}) => {
39
39
  const valid = inputSchema(request.event);
40
40
 
41
41
  if (!valid) {
42
- const error = createError(400, 'Event object failed validation');
43
- request.event.headers = { ...request.event.headers
44
- };
45
-
46
42
  if (i18nEnabled) {
47
43
  const language = chooseLanguage(request.event, defaultLanguage);
48
44
  localize[language](inputSchema.errors);
49
45
  }
50
46
 
51
- error.details = inputSchema.errors;
52
- throw error;
47
+ throw createError(400, 'Event object failed validation', {
48
+ cause: inputSchema.errors
49
+ });
53
50
  }
54
51
  };
55
52
 
@@ -57,10 +54,9 @@ const validatorMiddleware = (opts = {}) => {
57
54
  const valid = outputSchema(request.response);
58
55
 
59
56
  if (!valid) {
60
- const error = createError(500, 'Response object failed validation');
61
- error.details = outputSchema.errors;
62
- error.response = request.response;
63
- throw error;
57
+ throw createError(500, 'Response object failed validation', {
58
+ cause: outputSchema.errors
59
+ });
64
60
  }
65
61
  };
66
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/validator",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.5",
4
4
  "description": "Validator middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -18,7 +18,8 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "test": "npm run test:unit",
21
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
22
23
  },
23
24
  "license": "MIT",
24
25
  "keywords": [
@@ -46,16 +47,16 @@
46
47
  },
47
48
  "homepage": "https://github.com/middyjs/middy#readme",
48
49
  "dependencies": {
49
- "@middy/util": "^3.0.0-alpha.1",
50
+ "@middy/util": "^3.0.0-alpha.5",
50
51
  "ajv": "8.8.2",
51
52
  "ajv-formats": "2.1.1",
52
53
  "ajv-formats-draft2019": "1.6.1",
53
54
  "ajv-i18n": "4.2.0"
54
55
  },
55
56
  "devDependencies": {
56
- "@middy/core": "^3.0.0-alpha.1",
57
+ "@middy/core": "^3.0.0-alpha.5",
57
58
  "@types/http-errors": "^1.8.1",
58
59
  "ajv-bsontype": "^1.0.7"
59
60
  },
60
- "gitHead": "a14125c6b2e21b181824f9985a919a47f1e4711f"
61
+ "gitHead": "cf6a1b02a2e163bea353b10146d67e0d95ef8072"
61
62
  }