@middy/validator 5.0.1 → 5.0.3
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/index.js +1 -4
- package/package.json +4 -4
- package/transpile.js +2 -28
package/index.js
CHANGED
|
@@ -17,10 +17,9 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
17
17
|
if (!validEvent) {
|
|
18
18
|
const localize = languages[request.context.preferredLanguage] ?? languages[defaultLanguage];
|
|
19
19
|
localize?.(eventSchema.errors);
|
|
20
|
-
// Bad Request
|
|
21
20
|
throw createError(400, 'Event object failed validation', {
|
|
22
21
|
cause: {
|
|
23
|
-
|
|
22
|
+
package: '@middy/validator',
|
|
24
23
|
data: eventSchema.errors
|
|
25
24
|
}
|
|
26
25
|
});
|
|
@@ -29,7 +28,6 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
29
28
|
if (contextSchema) {
|
|
30
29
|
const validContext = await contextSchema(request.context);
|
|
31
30
|
if (!validContext) {
|
|
32
|
-
// Internal Server Error
|
|
33
31
|
throw createError(500, 'Context object failed validation', {
|
|
34
32
|
cause: {
|
|
35
33
|
package: '@middy/validator',
|
|
@@ -42,7 +40,6 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
42
40
|
const validatorMiddlewareAfter = async (request)=>{
|
|
43
41
|
const validResponse = await responseSchema(request.response);
|
|
44
42
|
if (!validResponse) {
|
|
45
|
-
// Internal Server Error
|
|
46
43
|
throw createError(500, 'Response object failed validation', {
|
|
47
44
|
cause: {
|
|
48
45
|
package: '@middy/validator',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/validator",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Validator middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"url": "https://github.com/sponsors/willfarrell"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@middy/util": "5.0.
|
|
70
|
+
"@middy/util": "5.0.3",
|
|
71
71
|
"ajv": "8.12.0",
|
|
72
72
|
"ajv-errors": "3.0.0",
|
|
73
73
|
"ajv-formats": "2.1.1",
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
"fast-uri": "2.3.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@middy/core": "5.0.
|
|
80
|
+
"@middy/core": "5.0.3",
|
|
81
81
|
"@types/http-errors": "^2.0.0",
|
|
82
82
|
"ajv-bsontype": "^1.0.7",
|
|
83
83
|
"ajv-cmd": "0.3.4"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "87660575a7ac2b52e4153c407a4c63c9449dcd0d"
|
|
86
86
|
}
|
package/transpile.js
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import compileSchema from 'ajv-cmd/compile'
|
|
3
|
-
import transpileFTL from 'ajv-cmd/ftl'
|
|
4
|
-
|
|
5
|
-
const ajvDefaults = {
|
|
6
|
-
strict: true,
|
|
7
|
-
coerceTypes: 'array', // important for query string params
|
|
8
|
-
allErrors: true,
|
|
9
|
-
useDefaults: 'empty',
|
|
10
|
-
messages: true // needs to be true to allow multi-locale errorMessage to work
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// This is pulled out due to it's performance cost (50-100ms on cold start)
|
|
14
|
-
// Precompile your schema during a build step is recommended.
|
|
15
|
-
export const transpileSchema = (schema, ajvOptions) => {
|
|
16
|
-
const options = { ...ajvDefaults, ...ajvOptions }
|
|
17
|
-
return compileSchema(schema, options)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const transpileLocale = transpileFTL
|
|
21
|
-
*/ import Ajv from 'ajv/dist/2020.js';
|
|
1
|
+
import Ajv from 'ajv/dist/2020.js';
|
|
22
2
|
import ajvFormats from 'ajv-formats';
|
|
23
3
|
import ajvFormatsDraft2019 from 'ajv-formats-draft2019';
|
|
24
4
|
import ajvKeywords from 'ajv-keywords';
|
|
25
5
|
import ajvErrors from 'ajv-errors';
|
|
26
6
|
import uriResolver from 'fast-uri';
|
|
27
7
|
import { transpile } from 'ajv-ftl-i18n';
|
|
28
|
-
// import transpileFTL from 'ajv-cmd/ftl'
|
|
29
8
|
export const transpileFTL = transpile;
|
|
30
|
-
// *** Start `ajv-cmd/compile` *** //
|
|
31
|
-
// import compileSchema from 'ajv-cmd/compile'
|
|
32
9
|
const defaultOptions = {
|
|
33
10
|
uriResolver
|
|
34
11
|
};
|
|
@@ -54,16 +31,13 @@ const compileSchema = (schema, options = {})=>{
|
|
|
54
31
|
const ajv = instance(options);
|
|
55
32
|
return ajv.compile(schema);
|
|
56
33
|
};
|
|
57
|
-
// *** End `ajv-cmd/compile` *** //
|
|
58
34
|
const ajvDefaults = {
|
|
59
35
|
strict: true,
|
|
60
36
|
coerceTypes: 'array',
|
|
61
37
|
allErrors: true,
|
|
62
38
|
useDefaults: 'empty',
|
|
63
|
-
messages: true
|
|
39
|
+
messages: true
|
|
64
40
|
};
|
|
65
|
-
// This is pulled out due to it's performance cost (50-100ms on cold start)
|
|
66
|
-
// Precompile your schema during a build step is recommended.
|
|
67
41
|
export const transpileSchema = (schema, ajvOptions)=>{
|
|
68
42
|
const options = {
|
|
69
43
|
...ajvDefaults,
|