-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathtypes.ts
104 lines (97 loc) · 2.29 KB
/
types.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type {
JSONValue,
JSONArray,
} from '@aws-lambda-powertools/commons/types';
import type { Functions } from './Functions.js';
import { BINDING_POWER } from './constants.js';
/**
* A token in the JMESPath AST.
*/
type Token = {
type: keyof typeof BINDING_POWER;
value: JSONValue;
start: number;
end: number;
};
/**
* A node in the JMESPath AST.
*/
type Node = {
type: string;
children: Node[];
value?: JSONValue;
};
/**
* Options for parsing.
*
* You can use this type to customize the parsing of JMESPath expressions.
*
* For example, you can use this type to provide custom functions to the parser.
*
* @example
* ```typescript
* import { search } from '@aws-lambda-powertools/jmespath';
* import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
*
* const expression = 'powertools_json(@)';
*
* const result = search(expression, "{\n \"a\": 1\n}", {
* customFunctions: new PowertoolsFunctions(),
* });
* console.log(result); // { a: 1 }
* ```
*/
type JMESPathParsingOptions = {
/**
* The custom functions to use.
*
* By default, the interpreter uses the standard JMESPath functions
* available in the [JMESPath specification](https://jmespath.org/specification.html).
*/
customFunctions?: Functions;
};
/**
* Decorator for function signatures.
*/
type FunctionSignatureDecorator = (
target: Functions | typeof Functions,
propertyKey: string | symbol,
descriptor: PropertyDescriptor
) => void;
/**
* Options for a function signature.
*
* @example
* ```typescript
* import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
*
* class MyFunctions extends Functions {
* @Functions.signature({
* argumentsSpecs: [['number'], ['number']],
* variadic: true,
* })
* public funcMyMethod(args: Array<number>): unknown {
* // ...
* }
* }
* ```
*
* @param argumentsSpecs The expected arguments for the function.
* @param variadic Whether the function is variadic.
*/
type FunctionSignatureOptions = {
argumentsSpecs: Array<Array<string>>;
variadic?: boolean;
};
/**
* A JSON parseable object.
*/
type JSONObject = JSONArray | JSONValue | object;
export type {
FunctionSignatureDecorator,
FunctionSignatureOptions,
Node,
JMESPathParsingOptions,
Token,
JSONObject,
};