@aws-lambda-powertools/jmespath 0.0.0-alpha.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -0
- package/README.md +214 -5
- package/lib/cjs/Expression.d.ts +19 -0
- package/lib/cjs/Expression.d.ts.map +1 -0
- package/lib/cjs/Expression.js +38 -0
- package/lib/cjs/Functions.d.ts +242 -0
- package/lib/cjs/Functions.d.ts.map +1 -0
- package/lib/cjs/Functions.js +597 -0
- package/lib/cjs/Lexer.d.ts +19 -0
- package/lib/cjs/Lexer.d.ts.map +1 -0
- package/lib/cjs/Lexer.js +271 -0
- package/lib/cjs/ParsedResult.d.ts +15 -0
- package/lib/cjs/ParsedResult.d.ts.map +1 -0
- package/lib/cjs/ParsedResult.js +33 -0
- package/lib/cjs/Parser.d.ts +35 -0
- package/lib/cjs/Parser.d.ts.map +1 -0
- package/lib/cjs/Parser.js +506 -0
- package/lib/cjs/PowertoolsFunctions.d.ts +36 -0
- package/lib/cjs/PowertoolsFunctions.d.ts.map +1 -0
- package/lib/cjs/PowertoolsFunctions.js +69 -0
- package/lib/cjs/TreeInterpreter.d.ts +28 -0
- package/lib/cjs/TreeInterpreter.d.ts.map +1 -0
- package/lib/cjs/TreeInterpreter.js +313 -0
- package/lib/cjs/ast.d.ts +185 -0
- package/lib/cjs/ast.d.ts.map +1 -0
- package/lib/cjs/ast.js +275 -0
- package/lib/cjs/constants.d.ts +60 -0
- package/lib/cjs/constants.d.ts.map +1 -0
- package/lib/cjs/constants.js +96 -0
- package/lib/cjs/envelopes.d.ts +69 -0
- package/lib/cjs/envelopes.d.ts.map +1 -0
- package/lib/cjs/envelopes.js +90 -0
- package/lib/cjs/errors.d.ts +183 -0
- package/lib/cjs/errors.d.ts.map +1 -0
- package/lib/cjs/errors.js +206 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/search.d.ts +50 -0
- package/lib/cjs/search.d.ts.map +1 -0
- package/lib/cjs/search.js +55 -0
- package/lib/cjs/types.d.ts +88 -0
- package/lib/cjs/types.d.ts.map +1 -0
- package/lib/cjs/types.js +2 -0
- package/lib/cjs/utils.d.ts +87 -0
- package/lib/cjs/utils.d.ts.map +1 -0
- package/lib/cjs/utils.js +282 -0
- package/lib/esm/Expression.d.ts +19 -0
- package/lib/esm/Expression.d.ts.map +1 -0
- package/lib/esm/Expression.js +35 -0
- package/lib/esm/Functions.d.ts +242 -0
- package/lib/esm/Functions.d.ts.map +1 -0
- package/lib/esm/Functions.js +594 -0
- package/lib/esm/Lexer.d.ts +19 -0
- package/lib/esm/Lexer.d.ts.map +1 -0
- package/lib/esm/Lexer.js +268 -0
- package/lib/esm/ParsedResult.d.ts +15 -0
- package/lib/esm/ParsedResult.d.ts.map +1 -0
- package/lib/esm/ParsedResult.js +30 -0
- package/lib/esm/Parser.d.ts +35 -0
- package/lib/esm/Parser.d.ts.map +1 -0
- package/lib/esm/Parser.js +503 -0
- package/lib/esm/PowertoolsFunctions.d.ts +36 -0
- package/lib/esm/PowertoolsFunctions.d.ts.map +1 -0
- package/lib/esm/PowertoolsFunctions.js +66 -0
- package/lib/esm/TreeInterpreter.d.ts +28 -0
- package/lib/esm/TreeInterpreter.d.ts.map +1 -0
- package/lib/esm/TreeInterpreter.js +310 -0
- package/lib/esm/ast.d.ts +185 -0
- package/lib/esm/ast.d.ts.map +1 -0
- package/lib/esm/ast.js +251 -0
- package/lib/esm/constants.d.ts +60 -0
- package/lib/esm/constants.d.ts.map +1 -0
- package/lib/esm/constants.js +88 -0
- package/lib/esm/envelopes.d.ts +69 -0
- package/lib/esm/envelopes.d.ts.map +1 -0
- package/lib/esm/envelopes.js +74 -0
- package/lib/esm/errors.d.ts +183 -0
- package/lib/esm/errors.d.ts.map +1 -0
- package/lib/esm/errors.js +195 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/search.d.ts +50 -0
- package/lib/esm/search.d.ts.map +1 -0
- package/lib/esm/search.js +52 -0
- package/lib/esm/types.d.ts +88 -0
- package/lib/esm/types.d.ts.map +1 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils.d.ts +87 -0
- package/lib/esm/utils.d.ts.map +1 -0
- package/lib/esm/utils.js +275 -0
- package/package.json +51 -12
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is truthy.
|
|
3
|
+
*
|
|
4
|
+
* In JavaScript, zero is falsy while all other non-zero numbers are truthy.
|
|
5
|
+
* In JMESPath however, zero is truthy as well as all other non-zero numbers. For
|
|
6
|
+
* this reason we wrap the original isTruthy function from the commons package
|
|
7
|
+
* and add a check for numbers.
|
|
8
|
+
*
|
|
9
|
+
* @param value The value to check
|
|
10
|
+
*/
|
|
11
|
+
declare const isTruthy: (value: unknown) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Given a start, stop, and step value, the sub elements in an array are extracted as follows:
|
|
14
|
+
* * The first element in the extracted array is the index denoted by start.
|
|
15
|
+
* * The last element in the extracted array is the index denoted by end - 1.
|
|
16
|
+
* * The step value determines how many indices to skip after each element is selected from the array. An array of 1 (the default step) will not skip any indices. A step value of 2 will skip every other index while extracting elements from an array. A step value of -1 will extract values in reverse order from the array.
|
|
17
|
+
*
|
|
18
|
+
* Slice expressions adhere to the following rules:
|
|
19
|
+
* * If a negative start position is given, it is calculated as the total length of the array plus the given start position.
|
|
20
|
+
* * If no start position is given, it is assumed to be 0 if the given step is greater than 0 or the end of the array if the given step is less than 0.
|
|
21
|
+
* * If a negative stop position is given, it is calculated as the total length of the array plus the given stop position.
|
|
22
|
+
* * If no stop position is given, it is assumed to be the length of the array if the given step is greater than 0 or 0 if the given step is less than 0.
|
|
23
|
+
* * If the given step is omitted, it it assumed to be 1.
|
|
24
|
+
* * If the given step is 0, an invalid-value error MUST be raised (thrown before calling the function)
|
|
25
|
+
* * If the element being sliced is not an array, the result is null (returned before calling the function)
|
|
26
|
+
* * If the element being sliced is an array and yields no results, the result MUST be an empty array.
|
|
27
|
+
*
|
|
28
|
+
* @param array The array to slice
|
|
29
|
+
* @param start The start index
|
|
30
|
+
* @param end The end index
|
|
31
|
+
* @param step The step value
|
|
32
|
+
*/
|
|
33
|
+
declare const sliceArray: <T>({ array, start, end, step, }: {
|
|
34
|
+
array: T[];
|
|
35
|
+
start?: number;
|
|
36
|
+
end?: number;
|
|
37
|
+
step: number;
|
|
38
|
+
}) => T[] | null;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the number of arguments passed to a function matches the expected arity.
|
|
41
|
+
* If the number of arguments does not match the expected arity, an ArityError is thrown.
|
|
42
|
+
*
|
|
43
|
+
* If the function is variadic, then the number of arguments passed to the function must be
|
|
44
|
+
* greater than or equal to the expected arity. If the number of arguments passed to the function
|
|
45
|
+
* is less than the expected arity, a `VariadicArityError` is thrown.
|
|
46
|
+
*
|
|
47
|
+
* @param args The arguments passed to the function
|
|
48
|
+
* @param argumentsSpecs The expected types for each argument
|
|
49
|
+
* @param decoratedFuncName The name of the function being called
|
|
50
|
+
* @param variadic Whether the function is variadic
|
|
51
|
+
*/
|
|
52
|
+
declare const arityCheck: (args: unknown[], argumentsSpecs: Array<Array<string>>, variadic?: boolean) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Type checks the arguments passed to a function against the expected types.
|
|
55
|
+
*
|
|
56
|
+
* Type checking at runtime involves checking the top level type,
|
|
57
|
+
* and in the case of arrays, potentially checking the types of
|
|
58
|
+
* the elements in the array.
|
|
59
|
+
*
|
|
60
|
+
* If the list of types includes 'any', then the type check is a
|
|
61
|
+
* no-op.
|
|
62
|
+
*
|
|
63
|
+
* If the list of types includes more than one type, then the
|
|
64
|
+
* argument is checked against each type in the list. If the
|
|
65
|
+
* argument matches any of the types, then the type check
|
|
66
|
+
* passes. If the argument does not match any of the types, then
|
|
67
|
+
* a JMESPathTypeError is thrown.
|
|
68
|
+
*
|
|
69
|
+
* @param args The arguments passed to the function
|
|
70
|
+
* @param argumentsSpecs The expected types for each argument
|
|
71
|
+
*/
|
|
72
|
+
declare const typeCheck: (args: unknown[], argumentsSpecs: Array<Array<string>>) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Type checks an argument against a list of types.
|
|
75
|
+
*
|
|
76
|
+
* If the list of types includes more than one type, then the
|
|
77
|
+
* argument is checked against each type in the list. If the
|
|
78
|
+
* argument matches any of the types, then the type check
|
|
79
|
+
* passes. If the argument does not match any of the types, then
|
|
80
|
+
* a JMESPathTypeError is thrown.
|
|
81
|
+
*
|
|
82
|
+
* @param arg
|
|
83
|
+
* @param argumentSpec
|
|
84
|
+
*/
|
|
85
|
+
declare const typeCheckArgument: (arg: unknown, argumentSpec: Array<string>) => void;
|
|
86
|
+
export { isTruthy, arityCheck, sliceArray, typeCheck, typeCheckArgument };
|
|
87
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,QAAA,MAAM,QAAQ,UAAW,OAAO,KAAG,OAMlC,CAAC;AA4BF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,UAAU,oCAKb;IACD,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,KAAG,CAAC,EAAE,GAAG,IA0BT,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,UAAU,SACR,OAAO,EAAE,kBACC,MAAM,MAAM,MAAM,CAAC,CAAC,aACzB,OAAO,KACjB,IAcF,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,SAAS,SACP,OAAO,EAAE,kBACC,MAAM,MAAM,MAAM,CAAC,CAAC,KACnC,IAKF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,iBAAiB,QAAS,OAAO,gBAAgB,MAAM,MAAM,CAAC,KAAG,IAMtE,CAAC;AA4IF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/esm/utils.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { getType, isIntegerNumber, isRecord, isTruthy as isTruthyJS, isNumber, } from '@aws-lambda-powertools/commons/typeutils';
|
|
2
|
+
import { Expression } from './Expression.js';
|
|
3
|
+
import { ArityError, JMESPathTypeError, VariadicArityError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is truthy.
|
|
6
|
+
*
|
|
7
|
+
* In JavaScript, zero is falsy while all other non-zero numbers are truthy.
|
|
8
|
+
* In JMESPath however, zero is truthy as well as all other non-zero numbers. For
|
|
9
|
+
* this reason we wrap the original isTruthy function from the commons package
|
|
10
|
+
* and add a check for numbers.
|
|
11
|
+
*
|
|
12
|
+
* @param value The value to check
|
|
13
|
+
*/
|
|
14
|
+
const isTruthy = (value) => {
|
|
15
|
+
if (isNumber(value)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return isTruthyJS(value);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
* Cap a slice range value to the length of an array, taking into account
|
|
25
|
+
* negative values and whether the step is negative.
|
|
26
|
+
*
|
|
27
|
+
* @param arrayLength The length of the array
|
|
28
|
+
* @param value The value to cap
|
|
29
|
+
* @param isStepNegative Whether the step is negative
|
|
30
|
+
*/
|
|
31
|
+
const capSliceRange = (arrayLength, value, isStepNegative) => {
|
|
32
|
+
if (value < 0) {
|
|
33
|
+
value += arrayLength;
|
|
34
|
+
if (value < 0) {
|
|
35
|
+
value = isStepNegative ? -1 : 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (value >= arrayLength) {
|
|
39
|
+
value = isStepNegative ? arrayLength - 1 : arrayLength;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Given a start, stop, and step value, the sub elements in an array are extracted as follows:
|
|
45
|
+
* * The first element in the extracted array is the index denoted by start.
|
|
46
|
+
* * The last element in the extracted array is the index denoted by end - 1.
|
|
47
|
+
* * The step value determines how many indices to skip after each element is selected from the array. An array of 1 (the default step) will not skip any indices. A step value of 2 will skip every other index while extracting elements from an array. A step value of -1 will extract values in reverse order from the array.
|
|
48
|
+
*
|
|
49
|
+
* Slice expressions adhere to the following rules:
|
|
50
|
+
* * If a negative start position is given, it is calculated as the total length of the array plus the given start position.
|
|
51
|
+
* * If no start position is given, it is assumed to be 0 if the given step is greater than 0 or the end of the array if the given step is less than 0.
|
|
52
|
+
* * If a negative stop position is given, it is calculated as the total length of the array plus the given stop position.
|
|
53
|
+
* * If no stop position is given, it is assumed to be the length of the array if the given step is greater than 0 or 0 if the given step is less than 0.
|
|
54
|
+
* * If the given step is omitted, it it assumed to be 1.
|
|
55
|
+
* * If the given step is 0, an invalid-value error MUST be raised (thrown before calling the function)
|
|
56
|
+
* * If the element being sliced is not an array, the result is null (returned before calling the function)
|
|
57
|
+
* * If the element being sliced is an array and yields no results, the result MUST be an empty array.
|
|
58
|
+
*
|
|
59
|
+
* @param array The array to slice
|
|
60
|
+
* @param start The start index
|
|
61
|
+
* @param end The end index
|
|
62
|
+
* @param step The step value
|
|
63
|
+
*/
|
|
64
|
+
const sliceArray = ({ array, start, end, step, }) => {
|
|
65
|
+
const isStepNegative = step < 0;
|
|
66
|
+
const length = array.length;
|
|
67
|
+
const defaultStart = isStepNegative ? length - 1 : 0;
|
|
68
|
+
const defaultEnd = isStepNegative ? -1 : length;
|
|
69
|
+
start = isIntegerNumber(start)
|
|
70
|
+
? capSliceRange(length, start, isStepNegative)
|
|
71
|
+
: defaultStart;
|
|
72
|
+
end = isIntegerNumber(end)
|
|
73
|
+
? capSliceRange(length, end, isStepNegative)
|
|
74
|
+
: defaultEnd;
|
|
75
|
+
const result = [];
|
|
76
|
+
if (step > 0) {
|
|
77
|
+
for (let i = start; i < end; i += step) {
|
|
78
|
+
result.push(array[i]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
for (let i = start; i > end; i += step) {
|
|
83
|
+
result.push(array[i]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the number of arguments passed to a function matches the expected arity.
|
|
90
|
+
* If the number of arguments does not match the expected arity, an ArityError is thrown.
|
|
91
|
+
*
|
|
92
|
+
* If the function is variadic, then the number of arguments passed to the function must be
|
|
93
|
+
* greater than or equal to the expected arity. If the number of arguments passed to the function
|
|
94
|
+
* is less than the expected arity, a `VariadicArityError` is thrown.
|
|
95
|
+
*
|
|
96
|
+
* @param args The arguments passed to the function
|
|
97
|
+
* @param argumentsSpecs The expected types for each argument
|
|
98
|
+
* @param decoratedFuncName The name of the function being called
|
|
99
|
+
* @param variadic Whether the function is variadic
|
|
100
|
+
*/
|
|
101
|
+
const arityCheck = (args, argumentsSpecs, variadic) => {
|
|
102
|
+
if (variadic) {
|
|
103
|
+
if (args.length < argumentsSpecs.length) {
|
|
104
|
+
throw new VariadicArityError({
|
|
105
|
+
expectedArity: argumentsSpecs.length,
|
|
106
|
+
actualArity: args.length,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (args.length !== argumentsSpecs.length) {
|
|
111
|
+
throw new ArityError({
|
|
112
|
+
expectedArity: argumentsSpecs.length,
|
|
113
|
+
actualArity: args.length,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Type checks the arguments passed to a function against the expected types.
|
|
119
|
+
*
|
|
120
|
+
* Type checking at runtime involves checking the top level type,
|
|
121
|
+
* and in the case of arrays, potentially checking the types of
|
|
122
|
+
* the elements in the array.
|
|
123
|
+
*
|
|
124
|
+
* If the list of types includes 'any', then the type check is a
|
|
125
|
+
* no-op.
|
|
126
|
+
*
|
|
127
|
+
* If the list of types includes more than one type, then the
|
|
128
|
+
* argument is checked against each type in the list. If the
|
|
129
|
+
* argument matches any of the types, then the type check
|
|
130
|
+
* passes. If the argument does not match any of the types, then
|
|
131
|
+
* a JMESPathTypeError is thrown.
|
|
132
|
+
*
|
|
133
|
+
* @param args The arguments passed to the function
|
|
134
|
+
* @param argumentsSpecs The expected types for each argument
|
|
135
|
+
*/
|
|
136
|
+
const typeCheck = (args, argumentsSpecs) => {
|
|
137
|
+
for (const [index, argumentSpec] of argumentsSpecs.entries()) {
|
|
138
|
+
if (argumentSpec[0] === 'any')
|
|
139
|
+
continue;
|
|
140
|
+
typeCheckArgument(args[index], argumentSpec);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Type checks an argument against a list of types.
|
|
145
|
+
*
|
|
146
|
+
* If the list of types includes more than one type, then the
|
|
147
|
+
* argument is checked against each type in the list. If the
|
|
148
|
+
* argument matches any of the types, then the type check
|
|
149
|
+
* passes. If the argument does not match any of the types, then
|
|
150
|
+
* a JMESPathTypeError is thrown.
|
|
151
|
+
*
|
|
152
|
+
* @param arg
|
|
153
|
+
* @param argumentSpec
|
|
154
|
+
*/
|
|
155
|
+
const typeCheckArgument = (arg, argumentSpec) => {
|
|
156
|
+
let valid = false;
|
|
157
|
+
argumentSpec.forEach((type, index) => {
|
|
158
|
+
if (valid)
|
|
159
|
+
return;
|
|
160
|
+
valid = checkIfArgumentTypeIsValid(arg, type, index, argumentSpec);
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Check if the argument is of the expected type.
|
|
165
|
+
*
|
|
166
|
+
* @param arg The argument to check
|
|
167
|
+
* @param type The expected type
|
|
168
|
+
* @param index The index of the type we are checking
|
|
169
|
+
* @param argumentSpec The list of types to check against
|
|
170
|
+
*/
|
|
171
|
+
const checkIfArgumentTypeIsValid = (arg, type, index, argumentSpec) => {
|
|
172
|
+
const hasMoreTypesToCheck = index < argumentSpec.length - 1;
|
|
173
|
+
if (type.startsWith('array')) {
|
|
174
|
+
if (!Array.isArray(arg)) {
|
|
175
|
+
if (hasMoreTypesToCheck) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
throw new JMESPathTypeError({
|
|
179
|
+
currentValue: arg,
|
|
180
|
+
expectedTypes: argumentSpec,
|
|
181
|
+
actualType: getType(arg),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
checkComplexArrayType(arg, type, hasMoreTypesToCheck);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (type === 'expression') {
|
|
188
|
+
checkExpressionType(arg, argumentSpec, hasMoreTypesToCheck);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
else if (['string', 'number', 'boolean'].includes(type)) {
|
|
192
|
+
typeCheckType(arg, type, argumentSpec, hasMoreTypesToCheck);
|
|
193
|
+
if (typeof arg === type)
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
else if (type === 'object') {
|
|
197
|
+
checkObjectType(arg, argumentSpec, hasMoreTypesToCheck);
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Check if the argument is of the expected type.
|
|
204
|
+
*
|
|
205
|
+
* @param arg The argument to check
|
|
206
|
+
* @param type The type to check against
|
|
207
|
+
* @param argumentSpec The list of types to check against
|
|
208
|
+
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
209
|
+
*/
|
|
210
|
+
const typeCheckType = (arg, type, argumentSpec, hasMoreTypesToCheck) => {
|
|
211
|
+
if (typeof arg !== type && !hasMoreTypesToCheck) {
|
|
212
|
+
throw new JMESPathTypeError({
|
|
213
|
+
currentValue: arg,
|
|
214
|
+
expectedTypes: argumentSpec,
|
|
215
|
+
actualType: getType(arg),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Check if the argument is an array of complex types.
|
|
221
|
+
*
|
|
222
|
+
* @param arg The argument to check
|
|
223
|
+
* @param type The type to check against
|
|
224
|
+
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
225
|
+
*/
|
|
226
|
+
const checkComplexArrayType = (arg, type, hasMoreTypesToCheck) => {
|
|
227
|
+
if (!type.includes('-'))
|
|
228
|
+
return;
|
|
229
|
+
const arrayItemsType = type.slice(6);
|
|
230
|
+
let actualType;
|
|
231
|
+
for (const element of arg) {
|
|
232
|
+
try {
|
|
233
|
+
typeCheckArgument(element, [arrayItemsType]);
|
|
234
|
+
actualType = arrayItemsType;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
if (!hasMoreTypesToCheck || actualType !== undefined) {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Check if the argument is an expression.
|
|
245
|
+
*
|
|
246
|
+
* @param arg The argument to check
|
|
247
|
+
* @param type The type to check against
|
|
248
|
+
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
249
|
+
*/
|
|
250
|
+
const checkExpressionType = (arg, type, hasMoreTypesToCheck) => {
|
|
251
|
+
if (!(arg instanceof Expression) && !hasMoreTypesToCheck) {
|
|
252
|
+
throw new JMESPathTypeError({
|
|
253
|
+
currentValue: arg,
|
|
254
|
+
expectedTypes: type,
|
|
255
|
+
actualType: getType(arg),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Check if the argument is an object.
|
|
261
|
+
*
|
|
262
|
+
* @param arg The argument to check
|
|
263
|
+
* @param type The type to check against
|
|
264
|
+
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
265
|
+
*/
|
|
266
|
+
const checkObjectType = (arg, type, hasMoreTypesToCheck) => {
|
|
267
|
+
if (!isRecord(arg) && !hasMoreTypesToCheck) {
|
|
268
|
+
throw new JMESPathTypeError({
|
|
269
|
+
currentValue: arg,
|
|
270
|
+
expectedTypes: type,
|
|
271
|
+
actualType: getType(arg),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
export { isTruthy, arityCheck, sliceArray, typeCheck, typeCheckArgument };
|
package/package.json
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-lambda-powertools/jmespath",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Amazon Web Services",
|
|
7
7
|
"url": "https://aws.amazon.com"
|
|
8
8
|
},
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript",
|
|
13
9
|
"license": "MIT-0",
|
|
14
|
-
"
|
|
15
|
-
"types": "./lib/index.d.ts",
|
|
16
|
-
"files": [
|
|
17
|
-
"lib"
|
|
18
|
-
],
|
|
10
|
+
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript",
|
|
19
11
|
"repository": {
|
|
20
12
|
"type": "git",
|
|
21
13
|
"url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git"
|
|
@@ -23,7 +15,6 @@
|
|
|
23
15
|
"bugs": {
|
|
24
16
|
"url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues"
|
|
25
17
|
},
|
|
26
|
-
"dependencies": {},
|
|
27
18
|
"keywords": [
|
|
28
19
|
"aws",
|
|
29
20
|
"lambda",
|
|
@@ -33,5 +24,53 @@
|
|
|
33
24
|
"typescript",
|
|
34
25
|
"nodejs"
|
|
35
26
|
],
|
|
36
|
-
"
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@aws-lambda-powertools/commons": "^2.0.4"
|
|
29
|
+
},
|
|
30
|
+
"main": "./lib/cjs/index.js",
|
|
31
|
+
"types": "./lib/cjs/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"lib"
|
|
34
|
+
],
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./lib/cjs/index.d.ts",
|
|
40
|
+
"default": "./lib/cjs/index.js"
|
|
41
|
+
},
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./lib/esm/index.d.ts",
|
|
44
|
+
"default": "./lib/esm/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./envelopes": {
|
|
48
|
+
"import": "./lib/esm/envelopes.js",
|
|
49
|
+
"require": "./lib/cjs/envelopes.js"
|
|
50
|
+
},
|
|
51
|
+
"./functions": {
|
|
52
|
+
"import": "./lib/esm/PowertoolsFunctions.js",
|
|
53
|
+
"require": "./lib/cjs/PowertoolsFunctions.js"
|
|
54
|
+
},
|
|
55
|
+
"./types": {
|
|
56
|
+
"import": "./lib/esm/types.js",
|
|
57
|
+
"require": "./lib/cjs/types.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"typesVersions": {
|
|
61
|
+
"*": {
|
|
62
|
+
"envelopes": [
|
|
63
|
+
"lib/cjs/envelopes.d.ts",
|
|
64
|
+
"lib/esm/envelopes.d.ts"
|
|
65
|
+
],
|
|
66
|
+
"functions": [
|
|
67
|
+
"lib/cjs/PowertoolsFunctions.d.ts",
|
|
68
|
+
"lib/esm/PowertoolsFunctions.d.ts"
|
|
69
|
+
],
|
|
70
|
+
"types": [
|
|
71
|
+
"lib/cjs/types.d.ts",
|
|
72
|
+
"lib/esm/types.d.ts"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
37
76
|
}
|
package/lib/index.d.ts
DELETED
|
File without changes
|
package/lib/index.js
DELETED