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.

34 lines
1.5 KiB
JavaScript

"use strict";
const either = require("@validatem/either");
const wrapError = require("@validatem/wrap-error");
const isLiteralValue = require("../is-literal-value");
// NOTE: This validator should typically come last in an `either`, since it will catch various types of inputs (sqlExpression, literal values, etc.) that might need to be interpreted differently in specific contexts.
// FIXME: Rename valueExpression -> value?
module.exports = function (operations) {
const isObjectType = require("./is-object-type")(operations);
const isAnyFieldObject = require("./is-any-field-object")(operations);
const isAggregrateFunction = require("./is-aggregrate-function")(operations);
const isValueFunction = require("./is-value-function")(operations);
const wrapWithOperation = require("./wrap-with-operation")(operations);
return wrapError("Must be a type of value", either([
// Subqueries
[ isObjectType("producesResult") ],
// Raw SQL
[ isObjectType("sqlExpression") ],
// Functions
[ isValueFunction ], // FIXME: Is it possible for these to be invalid when collapsing, eg. when referencing non-collapsed columns?
[ isAggregrateFunction ], // FIXME: Make sure to check that this is only permitted when collapsing
// Field references
[ isAnyFieldObject ],
// Plain values
[ isObjectType("literalValue") ],
[ isObjectType("placeholder") ], // TODO: Verify that this also works for the `alias` method
[ isLiteralValue, wrapWithOperation("value") ]
]));
};