@middy/validator 3.2.0 → 3.3.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/index.cjs +21 -19
- package/index.js +4 -4
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
module
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Object.defineProperty(module, "exports", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>_default
|
|
8
|
+
});
|
|
9
|
+
const _util = require("@middy/util");
|
|
10
|
+
const _2020Js = _interopRequireDefault(require("ajv/dist/2020.js"));
|
|
11
|
+
const _ajvI18N = _interopRequireDefault(require("ajv-i18n"));
|
|
12
|
+
const _ajvFormats = _interopRequireDefault(require("ajv-formats"));
|
|
13
|
+
const _ajvFormatsDraft2019 = _interopRequireDefault(require("ajv-formats-draft2019"));
|
|
14
|
+
const _typeofJs = _interopRequireDefault(require("ajv-keywords/dist/definitions/typeof.js"));
|
|
15
|
+
const _fastUri = _interopRequireDefault(require("fast-uri"));
|
|
13
16
|
function _interopRequireDefault(obj) {
|
|
14
17
|
return obj && obj.__esModule ? obj : {
|
|
15
18
|
default: obj
|
|
@@ -25,7 +28,7 @@ const ajvDefaults = {
|
|
|
25
28
|
messages: false,
|
|
26
29
|
uriResolver: _fastUri.default,
|
|
27
30
|
keywords: [
|
|
28
|
-
(0, _typeofJs
|
|
31
|
+
(0, _typeofJs.default)()
|
|
29
32
|
]
|
|
30
33
|
};
|
|
31
34
|
const defaults = {
|
|
@@ -53,7 +56,7 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
53
56
|
const language = chooseLanguage(request.event, defaultLanguage);
|
|
54
57
|
_ajvI18N.default[language](eventSchema.errors);
|
|
55
58
|
}
|
|
56
|
-
const error = (0, _util
|
|
59
|
+
const error = (0, _util.createError)(400, 'Event object failed validation');
|
|
57
60
|
error.cause = eventSchema.errors;
|
|
58
61
|
throw error;
|
|
59
62
|
}
|
|
@@ -61,22 +64,22 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
61
64
|
if (contextSchema) {
|
|
62
65
|
const validContext = await contextSchema(request.context);
|
|
63
66
|
if (!validContext) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
throw
|
|
67
|
+
const error1 = (0, _util.createError)(500, 'Context object failed validation');
|
|
68
|
+
error1.cause = contextSchema.errors;
|
|
69
|
+
throw error1;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
};
|
|
70
73
|
const validatorMiddlewareAfter = async (request)=>{
|
|
71
74
|
const valid = await responseSchema(request.response);
|
|
72
75
|
if (!valid) {
|
|
73
|
-
const error = (0, _util
|
|
76
|
+
const error = (0, _util.createError)(500, 'Response object failed validation');
|
|
74
77
|
error.cause = responseSchema.errors;
|
|
75
78
|
throw error;
|
|
76
79
|
}
|
|
77
80
|
};
|
|
78
81
|
return {
|
|
79
|
-
before:
|
|
82
|
+
before: eventSchema ?? inputSchema ?? contextSchema ? validatorMiddlewareBefore : undefined,
|
|
80
83
|
after: responseSchema ?? outputSchema ? validatorMiddlewareAfter : undefined
|
|
81
84
|
};
|
|
82
85
|
};
|
|
@@ -88,8 +91,8 @@ const compile = (schema, ajvOptions, ajvInstance = null)=>{
|
|
|
88
91
|
};
|
|
89
92
|
if (!ajv) {
|
|
90
93
|
ajv = ajvInstance ?? new Ajv(options);
|
|
91
|
-
(0, _ajvFormats
|
|
92
|
-
(0, _ajvFormatsDraft2019
|
|
94
|
+
(0, _ajvFormats.default)(ajv);
|
|
95
|
+
(0, _ajvFormatsDraft2019.default)(ajv);
|
|
93
96
|
} else if (!ajvInstance) {
|
|
94
97
|
ajv.opts = {
|
|
95
98
|
...ajv.opts,
|
|
@@ -118,8 +121,7 @@ const chooseLanguage = ({ preferredLanguage }, defaultLanguage)=>{
|
|
|
118
121
|
}
|
|
119
122
|
return defaultLanguage;
|
|
120
123
|
};
|
|
121
|
-
|
|
122
|
-
module.exports = _default;
|
|
124
|
+
const _default = validatorMiddleware;
|
|
123
125
|
|
|
124
126
|
|
|
125
127
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -51,9 +51,9 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
51
51
|
if (contextSchema) {
|
|
52
52
|
const validContext = await contextSchema(request.context);
|
|
53
53
|
if (!validContext) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
throw
|
|
54
|
+
const error1 = createError(500, 'Context object failed validation');
|
|
55
|
+
error1.cause = contextSchema.errors;
|
|
56
|
+
throw error1;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
};
|
|
@@ -66,7 +66,7 @@ const validatorMiddleware = (opts = {})=>{
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
return {
|
|
69
|
-
before:
|
|
69
|
+
before: eventSchema ?? inputSchema ?? contextSchema ? validatorMiddlewareBefore : undefined,
|
|
70
70
|
after: responseSchema ?? outputSchema ? validatorMiddlewareAfter : undefined
|
|
71
71
|
};
|
|
72
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/validator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Validator middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://middy.js.org",
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@middy/util": "3.
|
|
64
|
+
"@middy/util": "3.3.0",
|
|
65
65
|
"ajv": "8.11.0",
|
|
66
66
|
"ajv-formats": "2.1.1",
|
|
67
67
|
"ajv-formats-draft2019": "1.6.1",
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"fast-uri": "2.1.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@middy/core": "3.
|
|
73
|
+
"@middy/core": "3.3.0",
|
|
74
74
|
"@types/http-errors": "^1.8.1",
|
|
75
75
|
"ajv-bsontype": "^1.0.7"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "33d459b619c2aaf55ac8640bc56e439178a62e8a"
|
|
78
78
|
}
|