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.
27 lines
934 B
JavaScript
27 lines
934 B
JavaScript
"use strict";
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
const required = require("@validatem/required");
|
|
const either = require("@validatem/either");
|
|
const isString = require("@validatem/is-string");
|
|
|
|
const node = require("../ast-node");
|
|
|
|
module.exports = function (operations) {
|
|
const isValueExpression = require("../validators/operations/is-value-expression")(operations);
|
|
const isObjectType = require("../validators/operations/is-object-type")(operations);
|
|
const wrapWithOperation = require("../validators/operations/wrap-with-operation")(operations);
|
|
|
|
return function alias(_name, _expression) {
|
|
let [ name, expression ] = validateArguments(arguments, {
|
|
name: [ required, either([
|
|
[ isObjectType("columnName") ],
|
|
[ isString, wrapWithOperation("column") ]
|
|
])],
|
|
expression: [ required, isValueExpression ]
|
|
});
|
|
|
|
return node({ type: "alias", column: name, expression: expression });
|
|
};
|
|
};
|