1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.sanitize = void 0;
|
4 | const chain_1 = require("../chain");
|
5 | const utils_1 = require("../utils");
|
6 | const context_builder_1 = require("../context-builder");
|
7 | let hasNotified = false;
|
8 | function sanitize(fields = '', locations = []) {
|
9 | if (!hasNotified) {
|
10 | hasNotified = true;
|
11 | console.warn('express-validator: sanitize(), sanitizeBody() and other sanitization-only middlewares ' +
|
12 | 'have been deprecated.\nPlease use check(), body() and others instead, which must offer ' +
|
13 | 'the same API, and more.');
|
14 | }
|
15 | const builder = new context_builder_1.ContextBuilder()
|
16 | .setFields(Array.isArray(fields) ? fields : [fields])
|
17 | .setLocations(locations);
|
18 | const runner = new chain_1.ContextRunnerImpl(builder);
|
19 | const middleware = async (req, _res, next) => {
|
20 | try {
|
21 | await runner.run(req);
|
22 | next();
|
23 | }
|
24 | catch (e) {
|
25 | next(e);
|
26 | }
|
27 | };
|
28 | return Object.assign(middleware, utils_1.bindAll(runner), utils_1.bindAll(new chain_1.SanitizersImpl(builder, middleware)), { builder });
|
29 | }
|
30 | exports.sanitize = sanitize;
|