• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

u-wave / core / 20825751473

08 Jan 2026 05:28PM UTC coverage: 86.058% (+0.006%) from 86.052%
20825751473

push

github

web-flow
Tighten up internal types in error handling (#738)

1009 of 1205 branches covered (83.73%)

Branch coverage included in aggregate %.

36 of 38 new or added lines in 5 files covered. (94.74%)

10565 of 12244 relevant lines covered (86.29%)

100.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.94
/src/middleware/schema.js
1
import assert from 'node:assert';
1✔
2
import fs from 'node:fs';
1✔
3
import Ajv from 'ajv/dist/2019.js';
1✔
4
import addFormats from 'ajv-formats';
1✔
5
import ValidationError from '../errors/ValidationError.js';
1✔
6

1✔
7
const ajv = new Ajv({
1✔
8
  coerceTypes: false,
1✔
9
  removeAdditional: true,
1✔
10
  useDefaults: true,
1✔
11
  ownProperties: true,
1✔
12
  allErrors: true,
1✔
13
});
1✔
14
addFormats(ajv);
1✔
15
ajv.addMetaSchema(JSON.parse(fs.readFileSync(new URL('../../node_modules/ajv/dist/refs/json-schema-draft-07.json', import.meta.url), 'utf8')));
1✔
16
ajv.addSchema(JSON.parse(fs.readFileSync(new URL('../schemas/definitions.json', import.meta.url), 'utf8')));
1✔
17

1✔
18
/** @type {import('ajv').ValidateFunction<unknown>} */
1✔
19
function alwaysTrue() {
321✔
20
  return true;
321✔
21
}
321✔
22
alwaysTrue.errors = null;
1✔
23

1✔
24
/**
1✔
25
 * @template T
1✔
26
 * @param {T | null | undefined} t
1✔
27
 * @returns {T}
1✔
28
 */
1✔
29
function assertNotNull(t) {
55✔
30
  assert(t, 'Unexpected null');
55✔
31
  return t;
55✔
32
}
55✔
33

1✔
34
/**
1✔
35
 * @typedef {object} Schemas
1✔
36
 * @prop {import('ajv').SchemaObject} [body]
1✔
37
 * @prop {import('ajv').SchemaObject} [params]
1✔
38
 * @prop {import('ajv').SchemaObject} [query]
1✔
39
 * @param {Schemas} schemas
1✔
40
 * @returns {import('express').RequestHandler}
1✔
41
 */
1✔
42
function schema({ body, params, query }) {
6,923✔
43
  const validateBody = body ? ajv.compile(body) : alwaysTrue;
6,923✔
44
  const validateParams = params ? ajv.compile(params) : alwaysTrue;
6,923✔
45
  const validateQuery = query ? ajv.compile(query) : alwaysTrue;
6,923✔
46
  return (req, res, next) => {
6,923✔
47
    if (!validateParams(req.params)) {
207!
NEW
48
      next(new ValidationError(assertNotNull(validateParams.errors), ajv));
×
49
      return;
×
50
    }
×
51
    if (!validateQuery(req.query)) {
207✔
52
      next(new ValidationError(assertNotNull(validateQuery.errors), ajv));
2✔
53
      return;
2✔
54
    }
2✔
55
    if (!validateBody(req.body)) {
207✔
56
      next(new ValidationError(assertNotNull(validateBody.errors), ajv));
53✔
57
      return;
53✔
58
    }
53✔
59
    next();
152✔
60
  };
6,923✔
61
}
6,923✔
62

1✔
63
export default schema;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc