File tree 2 files changed +878
-0
lines changed
2 files changed +878
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { TreeInterpreter } from './TreeInterpreter.js' ;
2
+ import {
3
+ ArityError ,
4
+ JMESPathTypeError ,
5
+ UnknownFunctionError ,
6
+ VariadicArityError ,
7
+ } from './errors.js' ;
8
+ import type { Node , ParsingOptions , JSONObject } from './types.js' ;
9
+
10
+ class ParsedResult {
11
+ public expression : string ;
12
+ public parsed : Node ;
13
+
14
+ public constructor ( expression : string , parsed : Node ) {
15
+ this . expression = expression ;
16
+ this . parsed = parsed ;
17
+ }
18
+
19
+ /**
20
+ * Perform a JMESPath search on a JSON value.
21
+ *
22
+ * @param value The JSON value to search
23
+ * @param options The parsing options to use
24
+ */
25
+ public search ( value : JSONObject , options ?: ParsingOptions ) : unknown {
26
+ const interpreter = new TreeInterpreter ( options ) ;
27
+
28
+ try {
29
+ return interpreter . visit ( this . parsed , value ) ;
30
+ } catch ( error ) {
31
+ if (
32
+ error instanceof JMESPathTypeError ||
33
+ error instanceof UnknownFunctionError ||
34
+ error instanceof ArityError ||
35
+ error instanceof VariadicArityError
36
+ ) {
37
+ error . setExpression ( this . expression ) ;
38
+ }
39
+ throw error ;
40
+ }
41
+ }
42
+ }
43
+
44
+ export { ParsedResult } ;
You can’t perform that action at this time.
0 commit comments