Skip to content

Commit 48bb9a7

Browse files
authored
refactor(jmespath): rename jmespath parsing options type (#2367)
* feat(idempotency): add custom jmespath functions * chore(layers): add package to layer * chore: move jmespath pkg up into build process * feat: enable custom functions * chore: move jmespath pkg up into build process * chore: update layer setup * refactor(jmespath): rename jmespath parsing options type * chore: updated occurrences * chore: merge conflicts
1 parent 9721e7c commit 48bb9a7

File tree

9 files changed

+28
-30
lines changed

9 files changed

+28
-30
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"description": "A suite of utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more.",
55
"workspaces": [
66
"packages/commons",
7+
"packages/jmespath",
78
"packages/logger",
89
"packages/metrics",
910
"packages/tracer",
1011
"packages/parameters",
1112
"packages/idempotency",
1213
"packages/batch",
1314
"packages/testing",
14-
"packages/jmespath",
1515
"packages/parser",
1616
"docs/snippets",
1717
"layers",

packages/idempotency/src/IdempotencyConfig.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
22
import type { Context } from 'aws-lambda';
33
import type { IdempotencyConfigOptions } from './types/IdempotencyOptions.js';
4-
import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types';
4+
import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types';
55
import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
66

77
/**
@@ -25,9 +25,13 @@ class IdempotencyConfig {
2525
*/
2626
public hashFunction: string;
2727
/**
28+
* Options for parsing JMESPath expressions.
2829
*
30+
* By default, you can use any of the {@link https://jmespath.org/specification.html | JMESPath built-in functions} as well as the
31+
* {@link https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_jmespath.PowertoolsFunctions.PowertoolsFunctions.html | custom functions provided}
32+
* by the `@aws-lambda-powertools/jmespath` package.
2933
*/
30-
public jmesPathOptions: ParsingOptions;
34+
public jmesPathOptions: JMESPathParsingOptions;
3135
/**
3236
* The lambda context object.
3337
*/

packages/idempotency/src/persistence/BasePersistenceLayer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHash, Hash } from 'node:crypto';
22
import { search } from '@aws-lambda-powertools/jmespath';
3-
import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types';
3+
import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types';
44
import type {
55
BasePersistenceLayerOptions,
66
BasePersistenceLayerInterface,
@@ -37,7 +37,7 @@ abstract class BasePersistenceLayer implements BasePersistenceLayerInterface {
3737
private throwOnNoIdempotencyKey = false;
3838
private useLocalCache = false;
3939
private validationKeyJmesPath?: string;
40-
#jmesPathOptions?: ParsingOptions;
40+
#jmesPathOptions?: JMESPathParsingOptions;
4141

4242
public constructor() {
4343
this.envVarsService = new EnvironmentVariablesService();

packages/jmespath/src/ParsedResult.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
UnknownFunctionError,
66
VariadicArityError,
77
} from './errors.js';
8-
import type { Node, ParsingOptions, JSONObject } from './types.js';
8+
import type { Node, JMESPathParsingOptions, JSONObject } from './types.js';
99

1010
class ParsedResult {
1111
public expression: string;
@@ -22,7 +22,7 @@ class ParsedResult {
2222
* @param value The JSON value to search
2323
* @param options The parsing options to use
2424
*/
25-
public search(value: JSONObject, options?: ParsingOptions): unknown {
25+
public search(value: JSONObject, options?: JMESPathParsingOptions): unknown {
2626
const interpreter = new TreeInterpreter(options);
2727

2828
try {

packages/jmespath/src/TreeInterpreter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from './errors.js';
1313
import { Expression } from './Expression.js';
1414
import { Functions } from './Functions.js';
15-
import type { Node, TreeInterpreterOptions, JSONObject } from './types.js';
15+
import type { Node, JMESPathParsingOptions, JSONObject } from './types.js';
1616
import { isTruthy, sliceArray } from './utils.js';
1717

1818
/**
@@ -30,7 +30,7 @@ class TreeInterpreter {
3030
/**
3131
* @param options The options to use for the interpreter.
3232
*/
33-
public constructor(options?: TreeInterpreterOptions) {
33+
public constructor(options?: JMESPathParsingOptions) {
3434
if (options?.customFunctions) {
3535
this.#functions = options.customFunctions;
3636
} else {

packages/jmespath/src/envelopes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { search } from './search.js';
22
import { PowertoolsFunctions } from './PowertoolsFunctions.js';
3-
import type { ParsingOptions, JSONObject } from './types.js';
3+
import type { JMESPathParsingOptions, JSONObject } from './types.js';
44

55
/**
66
* Searches and extracts data using JMESPath
@@ -57,7 +57,7 @@ import type { ParsingOptions, JSONObject } from './types.js';
5757
const extractDataFromEnvelope = <T>(
5858
data: JSONObject,
5959
envelope: string,
60-
options?: ParsingOptions
60+
options?: JMESPathParsingOptions
6161
): T => {
6262
if (!options) {
6363
options = { customFunctions: new PowertoolsFunctions() };

packages/jmespath/src/search.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Parser } from './Parser.js';
2-
import type { ParsingOptions, JSONObject } from './types.js';
2+
import type { JMESPathParsingOptions, JSONObject } from './types.js';
33

44
const parser = new Parser();
55

@@ -52,7 +52,7 @@ const parser = new Parser();
5252
const search = (
5353
expression: string,
5454
data: JSONObject,
55-
options?: ParsingOptions
55+
options?: JMESPathParsingOptions
5656
): unknown => {
5757
return parser.parse(expression).search(data, options);
5858
};

packages/jmespath/src/types.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@ type Node = {
2424
value?: JSONValue;
2525
};
2626

27-
/**
28-
* Options for the tree interpreter.
29-
*/
30-
type TreeInterpreterOptions = {
31-
/**
32-
* The custom functions to use.
33-
*
34-
* By default, the interpreter uses the standard JMESPath functions
35-
* available in the [JMESPath specification](https://jmespath.org/specification.html).
36-
*/
37-
customFunctions?: Functions;
38-
};
39-
4027
/**
4128
* Options for parsing.
4229
*
@@ -57,7 +44,15 @@ type TreeInterpreterOptions = {
5744
* console.log(result); // { a: 1 }
5845
* ```
5946
*/
60-
type ParsingOptions = TreeInterpreterOptions;
47+
type JMESPathParsingOptions = {
48+
/**
49+
* The custom functions to use.
50+
*
51+
* By default, the interpreter uses the standard JMESPath functions
52+
* available in the [JMESPath specification](https://jmespath.org/specification.html).
53+
*/
54+
customFunctions?: Functions;
55+
};
6156

6257
/**
6358
* Decorator for function signatures.
@@ -103,8 +98,7 @@ export type {
10398
FunctionSignatureDecorator,
10499
FunctionSignatureOptions,
105100
Node,
106-
ParsingOptions,
101+
JMESPathParsingOptions,
107102
Token,
108-
TreeInterpreterOptions,
109103
JSONObject,
110104
};

0 commit comments

Comments
 (0)