UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

45 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isANumericColumnParam = exports.isAColumnParam = exports.isAColumn = void 0; const constants_1 = require("../constants"); const dictionary_1 = require("../errors/dictionary"); const isAggregate_1 = require("./isAggregate"); function isAColumn(context) { return context.argument.type === constants_1.AST_TYPES.column; } exports.isAColumn = isAColumn; function isAColumnOrExternalFormula(context) { const isExternalFormula = context.argument.node .isExternalFormula; const isRawFunction = !(0, isAggregate_1.isAggregateFunction)(context.argument.node); //Must be a negation of the aggregate scope. return isAColumn(context) || (isExternalFormula && isRawFunction); } function isAColumnParam(param, _dataType, context) { let valid = false; if (param) valid = isAColumnOrExternalFormula(context); const baseResponse = { valid }; if (!valid) return Object.assign(Object.assign(Object.assign({}, baseResponse), { mismatchData: { type: constants_1.AST_TYPES.column, primitive: constants_1.AST_PRIMITIVES.UNKNOWN, } }), dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.missingColumnExpression]); return baseResponse; } exports.isAColumnParam = isAColumnParam; function isANumericColumnParam(param, dataType, context) { let valid = false; if (param) valid = isAColumnOrExternalFormula(context) && dataType === constants_1.AST_PRIMITIVES.NUMBER; const baseResponse = { valid }; if (!valid) return Object.assign(Object.assign(Object.assign({}, baseResponse), { mismatchData: { type: constants_1.AST_TYPES.column, primitive: constants_1.AST_PRIMITIVES.NUMBER, } }), dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.missingColumnExpression]); return baseResponse; } exports.isANumericColumnParam = isANumericColumnParam; //# sourceMappingURL=isAColumn.js.map