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
848 B
JavaScript
22 lines
848 B
JavaScript
"use strict";
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
const required = require("@validatem/required");
|
|
|
|
const node = require("../ast-node");
|
|
|
|
module.exports = function (operations) {
|
|
const isValueExpression = require("../validators/operations/is-value-expression")(operations);
|
|
const isField = require("../validators/operations/is-field");
|
|
|
|
return function alias(_name, _expression) {
|
|
let [ name, expression ] = validateArguments(arguments, {
|
|
name: [ required, isField ],
|
|
// FIXME: Make more strict to only accept column references, and expect the user to use compute for the rest (which should internally use an _expression type or so to pass into alias, during set-collapse-by-field)
|
|
expression: [ required, isValueExpression ]
|
|
});
|
|
|
|
return node({ type: "alias", field: name, expression: expression });
|
|
};
|
|
};
|