@momsfriendlydevco/cowboy 1.0.13 → 1.0.14

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.
@@ -1,10 +1,15 @@
1
1
  import joyful from '@momsfriendlydevco/joyful';
2
2
 
3
+ /**
4
+ * Run a Joi / Joyful validation function against a specific subkey within `req
5
+ *
6
+ * @param {String} subkey The subkey to run against
7
+ * @param {Function|Object} Callback to use with Joyful to validate with
8
+ * @returns {Void} Either a successful middleware cycle (if validatio succeeds) or a call to `res.status(400)` if failed
9
+ */
3
10
  export default function CowboyMiddlewareValidate(subkey, validator) {
4
11
  return (req, res) => {
5
- let joyfulResult = joyful({
6
- [subkey]: validator,
7
- });
12
+ let joyfulResult = joyful(req[subkey], validator);
8
13
 
9
14
  if (joyfulResult !== true) { // Failed body validation?
10
15
  return res
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateBody(validator) {
4
- return CowboyMiddlewareValidate('body', {
5
- body: validator,
6
- })
4
+ return CowboyMiddlewareValidate('body', validator);
7
5
  }
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateParams(validator) {
4
- return CowboyMiddlewareValidate('params', {
5
- params: validator,
6
- })
4
+ return CowboyMiddlewareValidate('params', validator);
7
5
  }
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateQuery(validator) {
4
- return CowboyMiddlewareValidate('query', {
5
- query: validator,
6
- })
4
+ return CowboyMiddlewareValidate('query', validator);
7
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momsfriendlydevco/cowboy",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Wrapper around Cloudflare Wrangler to provide a more Express-like experience",
5
5
  "scripts": {
6
6
  "lint": "eslint ."