@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.
Files changed (97) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +214 -5
  3. package/lib/cjs/Expression.d.ts +19 -0
  4. package/lib/cjs/Expression.d.ts.map +1 -0
  5. package/lib/cjs/Expression.js +38 -0
  6. package/lib/cjs/Functions.d.ts +242 -0
  7. package/lib/cjs/Functions.d.ts.map +1 -0
  8. package/lib/cjs/Functions.js +597 -0
  9. package/lib/cjs/Lexer.d.ts +19 -0
  10. package/lib/cjs/Lexer.d.ts.map +1 -0
  11. package/lib/cjs/Lexer.js +271 -0
  12. package/lib/cjs/ParsedResult.d.ts +15 -0
  13. package/lib/cjs/ParsedResult.d.ts.map +1 -0
  14. package/lib/cjs/ParsedResult.js +33 -0
  15. package/lib/cjs/Parser.d.ts +35 -0
  16. package/lib/cjs/Parser.d.ts.map +1 -0
  17. package/lib/cjs/Parser.js +506 -0
  18. package/lib/cjs/PowertoolsFunctions.d.ts +36 -0
  19. package/lib/cjs/PowertoolsFunctions.d.ts.map +1 -0
  20. package/lib/cjs/PowertoolsFunctions.js +69 -0
  21. package/lib/cjs/TreeInterpreter.d.ts +28 -0
  22. package/lib/cjs/TreeInterpreter.d.ts.map +1 -0
  23. package/lib/cjs/TreeInterpreter.js +313 -0
  24. package/lib/cjs/ast.d.ts +185 -0
  25. package/lib/cjs/ast.d.ts.map +1 -0
  26. package/lib/cjs/ast.js +275 -0
  27. package/lib/cjs/constants.d.ts +60 -0
  28. package/lib/cjs/constants.d.ts.map +1 -0
  29. package/lib/cjs/constants.js +96 -0
  30. package/lib/cjs/envelopes.d.ts +69 -0
  31. package/lib/cjs/envelopes.d.ts.map +1 -0
  32. package/lib/cjs/envelopes.js +90 -0
  33. package/lib/cjs/errors.d.ts +183 -0
  34. package/lib/cjs/errors.d.ts.map +1 -0
  35. package/lib/cjs/errors.js +206 -0
  36. package/lib/cjs/index.d.ts +3 -0
  37. package/lib/cjs/index.d.ts.map +1 -0
  38. package/lib/cjs/index.js +15 -0
  39. package/lib/cjs/package.json +1 -0
  40. package/lib/cjs/search.d.ts +50 -0
  41. package/lib/cjs/search.d.ts.map +1 -0
  42. package/lib/cjs/search.js +55 -0
  43. package/lib/cjs/types.d.ts +88 -0
  44. package/lib/cjs/types.d.ts.map +1 -0
  45. package/lib/cjs/types.js +2 -0
  46. package/lib/cjs/utils.d.ts +87 -0
  47. package/lib/cjs/utils.d.ts.map +1 -0
  48. package/lib/cjs/utils.js +282 -0
  49. package/lib/esm/Expression.d.ts +19 -0
  50. package/lib/esm/Expression.d.ts.map +1 -0
  51. package/lib/esm/Expression.js +35 -0
  52. package/lib/esm/Functions.d.ts +242 -0
  53. package/lib/esm/Functions.d.ts.map +1 -0
  54. package/lib/esm/Functions.js +594 -0
  55. package/lib/esm/Lexer.d.ts +19 -0
  56. package/lib/esm/Lexer.d.ts.map +1 -0
  57. package/lib/esm/Lexer.js +268 -0
  58. package/lib/esm/ParsedResult.d.ts +15 -0
  59. package/lib/esm/ParsedResult.d.ts.map +1 -0
  60. package/lib/esm/ParsedResult.js +30 -0
  61. package/lib/esm/Parser.d.ts +35 -0
  62. package/lib/esm/Parser.d.ts.map +1 -0
  63. package/lib/esm/Parser.js +503 -0
  64. package/lib/esm/PowertoolsFunctions.d.ts +36 -0
  65. package/lib/esm/PowertoolsFunctions.d.ts.map +1 -0
  66. package/lib/esm/PowertoolsFunctions.js +66 -0
  67. package/lib/esm/TreeInterpreter.d.ts +28 -0
  68. package/lib/esm/TreeInterpreter.d.ts.map +1 -0
  69. package/lib/esm/TreeInterpreter.js +310 -0
  70. package/lib/esm/ast.d.ts +185 -0
  71. package/lib/esm/ast.d.ts.map +1 -0
  72. package/lib/esm/ast.js +251 -0
  73. package/lib/esm/constants.d.ts +60 -0
  74. package/lib/esm/constants.d.ts.map +1 -0
  75. package/lib/esm/constants.js +88 -0
  76. package/lib/esm/envelopes.d.ts +69 -0
  77. package/lib/esm/envelopes.d.ts.map +1 -0
  78. package/lib/esm/envelopes.js +74 -0
  79. package/lib/esm/errors.d.ts +183 -0
  80. package/lib/esm/errors.d.ts.map +1 -0
  81. package/lib/esm/errors.js +195 -0
  82. package/lib/esm/index.d.ts +3 -0
  83. package/lib/esm/index.d.ts.map +1 -0
  84. package/lib/esm/index.js +2 -0
  85. package/lib/esm/package.json +1 -0
  86. package/lib/esm/search.d.ts +50 -0
  87. package/lib/esm/search.d.ts.map +1 -0
  88. package/lib/esm/search.js +52 -0
  89. package/lib/esm/types.d.ts +88 -0
  90. package/lib/esm/types.d.ts.map +1 -0
  91. package/lib/esm/types.js +1 -0
  92. package/lib/esm/utils.d.ts +87 -0
  93. package/lib/esm/utils.d.ts.map +1 -0
  94. package/lib/esm/utils.js +275 -0
  95. package/package.json +51 -12
  96. package/lib/index.d.ts +0 -0
  97. package/lib/index.js +0 -4
package/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,218 @@
1
1
  # Powertools for AWS Lambda (TypeScript) - JMESPath Utility <!-- omit in toc -->
2
2
 
3
- | ⚠️ **WARNING: Do not use this utility in production just yet!** ⚠️ |
4
- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
5
- | **This package is currently released as placeholder for the imminent launch**. <br /> The package is not intended for production usage, for additional info please reach out via our GitHub repository. |
3
+ Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/typescript/latest/#features).
6
4
 
7
- Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda-typescript/latest/#features).
5
+ You can use the package in both TypeScript and JavaScript code bases.
8
6
 
9
- You can use the package in both TypeScript and JavaScript code bases.
7
+ - [Intro](#intro)
8
+ - [Usage](#usage)
9
+ - [Basic usage](#basic-usage)
10
+ - [Extract data from envelopes](#extract-data-from-envelopes)
11
+ - [JMESPath custom functions](#jmespath-custom-functions)
12
+ - [Contribute](#contribute)
13
+ - [Roadmap](#roadmap)
14
+ - [Connect](#connect)
15
+ - [How to support Powertools for AWS Lambda (TypeScript)?](#how-to-support-powertools-for-aws-lambda-typescript)
16
+ - [Becoming a reference customer](#becoming-a-reference-customer)
17
+ - [Sharing your work](#sharing-your-work)
18
+ - [Using Lambda Layer](#using-lambda-layer)
19
+ - [License](#license)
20
+
21
+ ## Intro
22
+
23
+ The JMESPath utility is a high-level function to parse and extract data from JSON objects using JMESPath expressions.
24
+
25
+ ## Usage
26
+
27
+ To get started, install the library by running:
28
+
29
+ ```sh
30
+ npm i @aws-lambda-powertools/jmespath
31
+ ```
32
+
33
+ ### Basic usage
34
+
35
+ At its core, the library provides a utility function to extract data from a JSON object using a JMESPath expression.
36
+
37
+ ```ts
38
+ import { search } from '@aws-lambda-powertools/jmespath';
39
+ import { Logger } from '@aws-lambda-powertools/logger';
40
+
41
+ const logger = new Logger();
42
+
43
+ type MyEvent = {
44
+ foo: {
45
+ bar: string;
46
+ };
47
+ }
48
+
49
+ export const handler = async (event: MyEvent): Promise<void> => {
50
+ const result = search(event, 'foo.bar');
51
+ logger.info(result); // "baz"
52
+ };
53
+ ```
54
+
55
+ ### Extract data from envelopes
56
+
57
+ In some cases, you may want to extract data from an envelope. The library provides a utility function to help you work with envelopes and extract data from them.
58
+
59
+ ```ts
60
+ import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
61
+
62
+ type MyEvent = {
63
+ body: string; // "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"
64
+ deeplyNested: Array<{ someData: number[] }>;
65
+ };
66
+
67
+ type MessageBody = {
68
+ customerId: string;
69
+ };
70
+
71
+ export const handler = async (event: MyEvent): Promise<unknown> => {
72
+ const payload = extractDataFromEnvelope<MessageBody>(
73
+ event,
74
+ 'powertools_json(body)'
75
+ );
76
+ const { customerId } = payload; // now deserialized
77
+
78
+ // also works for fetching and flattening deeply nested data
79
+ const someData = extractDataFromEnvelope<number[]>(
80
+ event,
81
+ 'deeplyNested[*].someData[]'
82
+ );
83
+
84
+ return {
85
+ customerId,
86
+ message: 'success',
87
+ context: someData,
88
+ statusCode: 200,
89
+ };
90
+ };
91
+ ```
92
+
93
+ The library provides [a set of built-in envelopes](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/jmespath/#built-in-envelopes) to help you extract data from common event sources, such as S3, SQS, and SNS, and more.
94
+
95
+ ```ts
96
+ import {
97
+ extractDataFromEnvelope,
98
+ SQS,
99
+ } from '@aws-lambda-powertools/jmespath/envelopes';
100
+ import { Logger } from '@aws-lambda-powertools/logger';
101
+ import type { SQSEvent } from 'aws-lambda';
102
+
103
+ const logger = new Logger();
104
+
105
+ type MessageBody = {
106
+ customerId: string;
107
+ };
108
+
109
+ export const handler = async (event: SQSEvent): Promise<void> => {
110
+ const records = extractDataFromEnvelope<Array<MessageBody>>(event, SQS);
111
+ for (const record of records) {
112
+ // records is now a list containing the deserialized body of each message
113
+ const { customerId } = record;
114
+ logger.appendKeys({ customerId });
115
+ }
116
+ };
117
+ ```
118
+
119
+ ### JMESPath custom functions
120
+
121
+ In addition to all the [built-in JMESPath functions](https://jmespath.org/specification.html#built-in-functions), the library provides custom functions to help you work with complex data structures. For example, you can use the `powertools_json` function to parse a JSON string, or the `powertools_base64` function to decode a base64-encoded string:
122
+
123
+ ```ts
124
+ import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
125
+ import { Logger } from '@aws-lambda-powertools/logger';
126
+
127
+ const logger = new Logger();
128
+
129
+ export const handler = async (event: { payload: string }): Promise<void> => {
130
+ const data = extractDataFromEnvelope<string>(
131
+ event,
132
+ 'powertools_json(powertools_base64(payload))'
133
+ );
134
+
135
+ logger.info('Decoded payload', { data });
136
+ };
137
+ ```
138
+
139
+ Finally, you can also extend the library with your own custom functions. Below an example of how to create a custom function to decode a Brotli-compressed string.
140
+
141
+ ```ts
142
+ import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
143
+ import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
144
+ import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
145
+ import { Logger } from '@aws-lambda-powertools/logger';
146
+ import { brotliDecompressSync } from 'node:zlib';
147
+
148
+ const logger = new Logger();
149
+
150
+ class CustomFunctions extends PowertoolsFunctions {
151
+ @PowertoolsFunctions.signature({
152
+ argumentsSpecs: [['string']],
153
+ variadic: false,
154
+ })
155
+ public funcDecodeBrotliCompression(value: string): string {
156
+ const encoded = fromBase64(value, 'base64');
157
+ const uncompressed = brotliDecompressSync(encoded);
158
+
159
+ return uncompressed.toString();
160
+ }
161
+ }
162
+
163
+ export const handler = async (event: { payload: string }): Promise<void> => {
164
+ const message = extractDataFromEnvelope<string>(
165
+ event,
166
+ 'Records[*].decode_brotli_compression(notification) | [*].powertools_json(@).message',
167
+ { customFunctions: new CustomFunctions() }
168
+ );
169
+
170
+ logger.info('Decoded message', { message });
171
+ };
172
+ ```
173
+
174
+ ## Contribute
175
+
176
+ If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md).
177
+
178
+ ## Roadmap
179
+
180
+ The roadmap of Powertools for AWS Lambda (TypeScript) is driven by customers’ demand.
181
+ Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/aws-powertools/powertools-lambda-typescript/issues), or [creating new ones](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new/choose), in this GitHub repository.
182
+
183
+ ## Connect
184
+
185
+ * **Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
186
+ * **Email**: aws-lambda-powertools-feedback@amazon.com
187
+
188
+ ## How to support Powertools for AWS Lambda (TypeScript)?
189
+
190
+ ### Becoming a reference customer
191
+
192
+ Knowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by raising a [Support Powertools for AWS Lambda (TypeScript) (become a reference)](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E) issue.
193
+
194
+ The following companies, among others, use Powertools:
195
+
196
+ * [Hashnode](https://hashnode.com/)
197
+ * [Trek10](https://www.trek10.com/)
198
+ * [Elva](https://elva-group.com)
199
+ * [globaldatanet](https://globaldatanet.com/)
200
+ * [Bailey Nelson](https://www.baileynelson.com.au)
201
+ * [Perfect Post](https://www.perfectpost.fr)
202
+ * [Sennder](https://sennder.com/)
203
+ * [Certible](https://www.certible.com/)
204
+ * [tecRacer GmbH & Co. KG](https://www.tecracer.com/)
205
+ * [AppYourself](https://appyourself.net)
206
+ * [Alma Media](https://www.almamedia.fi)
207
+
208
+ ### Sharing your work
209
+
210
+ Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (TypeScript) [here](https://docs.powertools.aws.dev/lambda/typescript/latest/we_made_this).
211
+
212
+ ### Using Lambda Layer
213
+
214
+ This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency to not impact the development process.
215
+
216
+ ## License
217
+
218
+ This library is licensed under the MIT-0 License. See the LICENSE file.
@@ -0,0 +1,19 @@
1
+ import type { TreeInterpreter } from './TreeInterpreter.js';
2
+ import type { JSONObject, Node } from './types.js';
3
+ /**
4
+ * Apply a JMESPath expression to a JSON value.
5
+ */
6
+ declare class Expression {
7
+ #private;
8
+ constructor(expression: Node, interpreter: TreeInterpreter);
9
+ /**
10
+ * Evaluate the expression against a JSON value.
11
+ *
12
+ * @param value The JSON value to apply the expression to.
13
+ * @param node The node to visit.
14
+ * @returns The result of applying the expression to the value.
15
+ */
16
+ visit(value: JSONObject, node?: Node): JSONObject;
17
+ }
18
+ export { Expression };
19
+ //# sourceMappingURL=Expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Expression.d.ts","sourceRoot":"","sources":["../../src/Expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,cAAM,UAAU;;gBAIK,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe;IAKjE;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,UAAU;CAGzD;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Expression_expression, _Expression_interpreter;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Expression = void 0;
16
+ /**
17
+ * Apply a JMESPath expression to a JSON value.
18
+ */
19
+ class Expression {
20
+ constructor(expression, interpreter) {
21
+ _Expression_expression.set(this, void 0);
22
+ _Expression_interpreter.set(this, void 0);
23
+ __classPrivateFieldSet(this, _Expression_expression, expression, "f");
24
+ __classPrivateFieldSet(this, _Expression_interpreter, interpreter, "f");
25
+ }
26
+ /**
27
+ * Evaluate the expression against a JSON value.
28
+ *
29
+ * @param value The JSON value to apply the expression to.
30
+ * @param node The node to visit.
31
+ * @returns The result of applying the expression to the value.
32
+ */
33
+ visit(value, node) {
34
+ return __classPrivateFieldGet(this, _Expression_interpreter, "f").visit(node ?? __classPrivateFieldGet(this, _Expression_expression, "f"), value);
35
+ }
36
+ }
37
+ exports.Expression = Expression;
38
+ _Expression_expression = new WeakMap(), _Expression_interpreter = new WeakMap();
@@ -0,0 +1,242 @@
1
+ import type { JSONArray, JSONObject, JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { Expression } from './Expression.js';
3
+ import type { FunctionSignatureDecorator, FunctionSignatureOptions } from './types.js';
4
+ /**
5
+ * A class that contains the built-in JMESPath functions.
6
+ *
7
+ * The built-in functions are implemented as methods on the Functions class.
8
+ * Each method is decorated with the `@Function.signature()` decorator to enforce the
9
+ * arity and types of the arguments passed to the function at runtime.
10
+ *
11
+ * You can extend the Functions class to add custom functions by creating a new class
12
+ * that extends Functions and adding new methods to it.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { search } from '@aws-lambda-powertools/jmespath';
17
+ * import { Functions } from '@aws-lambda-powertools/jmespath/functions';
18
+ *
19
+ * class MyFunctions extends Functions {
20
+ * ⁣@Functions.signature({
21
+ * argumentsSpecs: [['number'], ['number']],
22
+ * variadic: true,
23
+ * })
24
+ * public funcMyMethod(args: Array<number>): unknown {
25
+ * // ...
26
+ * }
27
+ * }
28
+ *
29
+ * const myFunctions = new MyFunctions();
30
+ *
31
+ * search('myMethod(@)', {}, { customFunctions: new MyFunctions() });
32
+ * ```
33
+ */
34
+ declare class Functions {
35
+ methods: Set<string>;
36
+ /**
37
+ * Get the absolute value of the provided number.
38
+ *
39
+ * @param args The number to get the absolute value of
40
+ */
41
+ funcAbs(args: number): number;
42
+ /**
43
+ * Calculate the average of the numbers in the provided array.
44
+ *
45
+ * @param args The numbers to average
46
+ */
47
+ funcAvg(args: Array<number>): number;
48
+ /**
49
+ * Get the ceiling of the provided number.
50
+ *
51
+ * @param args The number to get the ceiling of
52
+ */
53
+ funcCeil(args: number): number;
54
+ /**
55
+ * Determine if the given value is contained in the provided array or string.
56
+ *
57
+ * @param haystack The array or string to check
58
+ * @param needle The value to check for
59
+ */
60
+ funcContains(haystack: string, needle: string): boolean;
61
+ /**
62
+ * Determines if the provided string ends with the provided suffix.
63
+ *
64
+ * @param str The string to check
65
+ * @param suffix The suffix to check for
66
+ */
67
+ funcEndsWith(str: string, suffix: string): boolean;
68
+ /**
69
+ * Get the floor of the provided number.
70
+ *
71
+ * @param args The number to get the floor of
72
+ */
73
+ funcFloor(args: number): number;
74
+ /**
75
+ * Join the provided array into a single string.
76
+ *
77
+ * @param separator The separator to use
78
+ * @param items The array of itmes to join
79
+ */
80
+ funcJoin(separator: string, items: Array<string>): string;
81
+ /**
82
+ * Get the keys of the provided object.
83
+ *
84
+ * @param arg The object to get the keys of
85
+ */
86
+ funcKeys(arg: JSONObject): string[];
87
+ /**
88
+ * Get the number of items in the provided item.
89
+ *
90
+ * @param arg The array to get the length of
91
+ */
92
+ funcLength(arg: string | Array<unknown> | Record<string, unknown>): number;
93
+ /**
94
+ * Map the provided function over the provided array.
95
+ *
96
+ * @param expression The expression to map over the array
97
+ * @param args The array to map the expression over
98
+ */
99
+ funcMap(expression: Expression, args: JSONArray): JSONArray | Array<unknown>;
100
+ /**
101
+ * Get the maximum value in the provided array.
102
+ *
103
+ * @param arg The array to get the maximum value of
104
+ */
105
+ funcMax(arg: Array<number | string>): number | string | null;
106
+ /**
107
+ * Get the item in the provided array that has the maximum value when the provided expression is evaluated.
108
+ *
109
+ * @param args The array of items to get the maximum value of
110
+ * @param expression The expression to evaluate for each item in the array
111
+ */
112
+ funcMaxBy(args: Array<JSONObject>, expression: Expression): JSONObject | null;
113
+ /**
114
+ * Merge the provided objects into a single object.
115
+ *
116
+ * Note that this is a shallow merge and will not merge nested objects.
117
+ *
118
+ * @param args The objects to merge
119
+ */
120
+ funcMerge(...args: Array<JSONObject>): JSONObject;
121
+ /**
122
+ * Get the minimum value in the provided array.
123
+ *
124
+ * @param arg The array to get the minimum value of
125
+ */
126
+ funcMin(arg: Array<number>): number | string | null;
127
+ /**
128
+ * Get the item in the provided array that has the minimum value when the provided expression is evaluated.
129
+ *
130
+ * @param args The array of items to get the minimum value of
131
+ * @param expression The expression to evaluate for each item in the array
132
+ */
133
+ funcMinBy(args: Array<JSONObject>, expression: Expression): JSONObject | null;
134
+ /**
135
+ * Get the first argument that does not evaluate to null.
136
+ * If all arguments evaluate to null, then null is returned.
137
+ *
138
+ * @param args The keys of the items to check
139
+ */
140
+ funcNotNull(...args: Array<JSONValue>): JSONValue | null;
141
+ /**
142
+ * Reverses the provided string or array.
143
+ *
144
+ * @param arg The string or array to reverse
145
+ */
146
+ funcReverse(arg: string | Array<unknown>): string | Array<unknown>;
147
+ /**
148
+ * Sort the provided array.
149
+ *
150
+ * @param arg The array to sort
151
+ */
152
+ funcSort(arg: Array<string> | Array<number>): Array<unknown>;
153
+ /**
154
+ * Sort the provided array by the provided expression.
155
+ *
156
+ * @param args The array to sort
157
+ * @param expression The expression to sort by
158
+ */
159
+ funcSortBy(args: Array<JSONValue>, expression: Expression): Array<unknown>;
160
+ /**
161
+ * Determines if the provided string starts with the provided prefix.
162
+ *
163
+ * @param str The string to check
164
+ * @param prefix The prefix to check for
165
+ */
166
+ funcStartsWith(str: string, prefix: string): boolean;
167
+ /**
168
+ * Sum the provided numbers.
169
+ *
170
+ * @param args The numbers to sum
171
+ */
172
+ funcSum(args: Array<number>): number;
173
+ /**
174
+ * Convert the provided value to an array.
175
+ *
176
+ * If the provided value is an array, then it is returned.
177
+ * Otherwise, the value is wrapped in an array and returned.
178
+ *
179
+ * @param arg The items to convert to an array
180
+ */
181
+ funcToArray(arg: JSONArray | Array<JSONValue>): Array<JSONValue> | JSONArray;
182
+ /**
183
+ * Convert the provided value to a number.
184
+ *
185
+ * If the provided value is a number, then it is returned.
186
+ * Otherwise, the value is converted to a number and returned.
187
+ *
188
+ * If the value cannot be converted to a number, then null is returned.
189
+ *
190
+ * @param arg The value to convert to a number
191
+ */
192
+ funcToNumber(arg: JSONValue): number | null;
193
+ /**
194
+ * Convert the provided value to a string.
195
+ *
196
+ * If the provided value is a string, then it is returned.
197
+ * Otherwise, the value is converted to a string and returned.
198
+ *
199
+ * @param arg The value to convert to a string
200
+ */
201
+ funcToString(arg: JSONValue): string;
202
+ /**
203
+ * Get the type of the provided value.
204
+ *
205
+ * @param arg The value to check the type of
206
+ */
207
+ funcType(arg: JSONValue): string;
208
+ /**
209
+ * Get the values of the provided object.
210
+ *
211
+ * @param arg The object to get the values of
212
+ */
213
+ funcValues(arg: JSONObject): JSONValue[];
214
+ introspectMethods(scope?: Functions): Set<string>;
215
+ /**
216
+ * Decorator to enforce the signature of a function at runtime.
217
+ *
218
+ * The signature decorator enforces the arity and types of the arguments
219
+ * passed to a function at runtime. If the arguments do not match the
220
+ * expected arity or types errors are thrown.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
225
+ *
226
+ * class MyFunctions extends Functions {
227
+ * ⁣@Functions.signature({
228
+ * argumentsSpecs: [['number'], ['number']],
229
+ * variadic: true,
230
+ * })
231
+ * public funcMyMethod(args: Array<number>): unknown {
232
+ * // ...
233
+ * }
234
+ * }
235
+ * ```
236
+ *
237
+ * @param options The options for the signature decorator
238
+ */
239
+ static signature(options: FunctionSignatureOptions): FunctionSignatureDecorator;
240
+ }
241
+ export { Functions };
242
+ //# sourceMappingURL=Functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Functions.d.ts","sourceRoot":"","sources":["../../src/Functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACV,MAAM,sCAAsC,CAAC;AAM9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EAEzB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,cAAM,SAAS;IACN,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IACxC;;;;OAIG;IAEI,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;OAIG;IAII,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;IAI3C;;;;OAIG;IAEI,QAAQ,CAAC,IAAI,EAAE,MA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