Blog/wwwroot/jsonql-js/index.js 820 B · 19 lines · raw · history

1 export { parseExpression } from './parser.js';
2 export { evaluate } from './evaluate.js';
3 export { parseQuery, executeQuery, query } from './query.js';
4 export { SqlSyntaxError, SqlEvaluationError } from './errors.js';
5
6 import { parseExpression } from './parser.js';
7 import { evaluate } from './evaluate.js';
8
9 /**
10 * Parses (if needed) and evaluates a SQL-like expression against a JSON context object.
11 * @param {string|import('./parser.js').Expr} source - expression text, or an already-parsed AST
12 * @param {Record<string, any>} context
13 * @param {{functions?: Record<string, (...args: any[]) => any>}} [options]
14 * @returns {any}
15 */
16 export function evaluateExpression(source, context, options) {
17 const ast = typeof source === 'string' ? parseExpression(source) : source;
18 return evaluate(ast, context, options);
19 }