You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
725 B
JavaScript

"use strict";
const wrapError = require("@validatem/wrap-error");
const isPlainObject = require("@validatem/is-plain-object");
const ValidationError = require("@validatem/error");
module.exports = function (operations) {
return function isObjectType(expectedType) {
// FIXME: Why not using allowExtraProperties + object syntax here?
// FIXME: Add AST node check
return wrapError(`Must be a query object of type '${expectedType}'`, [
isPlainObject,
function (value) {
if (value.type !== expectedType) {
// FIXME: Maybe figure out a better user-facing name for the concept of a 'query object' (query segment)?
throw new ValidationError(`Must be of type '${expectedType}'`);
}
}
]);
};
};