-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathParsedResult.ts
44 lines (39 loc) · 1.1 KB
/
ParsedResult.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { TreeInterpreter } from './TreeInterpreter.js';
import {
ArityError,
JMESPathTypeError,
UnknownFunctionError,
VariadicArityError,
} from './errors.js';
import type { JMESPathParsingOptions, JSONObject, Node } from './types.js';
class ParsedResult {
public expression: string;
public parsed: Node;
public constructor(expression: string, parsed: Node) {
this.expression = expression;
this.parsed = parsed;
}
/**
* Perform a JMESPath search on a JSON value.
*
* @param value The JSON value to search
* @param options The parsing options to use
*/
public search(value: JSONObject, options?: JMESPathParsingOptions): unknown {
const interpreter = new TreeInterpreter(options);
try {
return interpreter.visit(this.parsed, value);
} catch (error) {
if (
error instanceof JMESPathTypeError ||
error instanceof UnknownFunctionError ||
error instanceof ArityError ||
error instanceof VariadicArityError
) {
error.setExpression(this.expression);
}
throw error;
}
}
}
export { ParsedResult };