UNPKG

ts-flex-query

Version:
28 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SortExpression = void 0; const lodash_1 = require("lodash"); const evaluate_expression_1 = require("../helpers/evaluate-expression"); const evaluation_context_utils_1 = require("../helpers/evaluation-context-utils"); class SortExpression { get dataType() { return this.input.dataType; } constructor(input, variableSymbol, specs) { this.input = input; this.variableSymbol = variableSymbol; this.specs = specs; } evaluate(context) { const inputResult = (0, evaluate_expression_1.evaluateExpression)(this.input, context); if (!Array.isArray(inputResult)) { return undefined; } return (0, lodash_1.orderBy)(inputResult, this.specs.map((spec) => (value) => { const valueContext = (0, evaluation_context_utils_1.addVariable)(context, this.variableSymbol, value); return (0, evaluate_expression_1.evaluateExpression)(spec.value, valueContext); }), this.specs.map((spec) => spec.isAscending ? 'asc' : 'desc')); } } exports.SortExpression = SortExpression; //# sourceMappingURL=sort.js.map