From ee5c26c0669c0f51f26f9b48fda91651a97e5d30 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 15 Apr 2024 14:30:49 +0200 Subject: [PATCH 1/9] feat(idempotency): add custom jmespath functions --- package-lock.json | 2 +- packages/idempotency/src/persistence/BasePersistenceLayer.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 701a55c097..655338c03e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17508,4 +17508,4 @@ } } } -} +} \ No newline at end of file diff --git a/packages/idempotency/src/persistence/BasePersistenceLayer.ts b/packages/idempotency/src/persistence/BasePersistenceLayer.ts index f02cbe5b8f..8d032f538d 100644 --- a/packages/idempotency/src/persistence/BasePersistenceLayer.ts +++ b/packages/idempotency/src/persistence/BasePersistenceLayer.ts @@ -1,6 +1,5 @@ import { createHash, Hash } from 'node:crypto'; import { search } from '@aws-lambda-powertools/jmespath'; -import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types'; import type { BasePersistenceLayerOptions, BasePersistenceLayerInterface, From 4f660bf74a2a79f361f0dcbcc7db3d611f852652 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 15 Apr 2024 14:53:39 +0200 Subject: [PATCH 2/9] chore(layers): add package to layer --- layers/src/layer-publisher-stack.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index b4fb24f19f..cbbdebc105 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -69,6 +69,7 @@ export class LayerPublisherStack extends Stack { 'parameters', 'idempotency', 'batch', + 'jmespath', ]; // These files are relative to the tmp folder From 650b813cdbba273aebbda44f863c28c19bb6c890 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 15 Apr 2024 15:06:08 +0200 Subject: [PATCH 3/9] chore: move jmespath pkg up into build process --- .github/actions/cached-node-modules/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/cached-node-modules/action.yml b/.github/actions/cached-node-modules/action.yml index 465a38fc2f..83bdfa7b5c 100644 --- a/.github/actions/cached-node-modules/action.yml +++ b/.github/actions/cached-node-modules/action.yml @@ -44,6 +44,7 @@ runs: npm run build -w packages/tracer & \ npm run build -w packages/metrics & \ npm run build -w packages/parameters & \ + npm run build -w packages/jmespath & \ npm run build -w packages/idempotency & \ npm run build -w packages/batch & \ npm run build -w packages/testing From 512b70e23fcecc325970bb781b650ba9189dd196 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 15 Apr 2024 15:15:05 +0200 Subject: [PATCH 4/9] feat: enable custom functions --- packages/idempotency/src/persistence/BasePersistenceLayer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/idempotency/src/persistence/BasePersistenceLayer.ts b/packages/idempotency/src/persistence/BasePersistenceLayer.ts index 8d032f538d..f02cbe5b8f 100644 --- a/packages/idempotency/src/persistence/BasePersistenceLayer.ts +++ b/packages/idempotency/src/persistence/BasePersistenceLayer.ts @@ -1,5 +1,6 @@ import { createHash, Hash } from 'node:crypto'; import { search } from '@aws-lambda-powertools/jmespath'; +import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types'; import type { BasePersistenceLayerOptions, BasePersistenceLayerInterface, From 0e17b651fdff341b3234fe592d5e6e2759d1268e Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 15 Apr 2024 15:25:27 +0200 Subject: [PATCH 5/9] chore: move jmespath pkg up into build process --- .github/actions/cached-node-modules/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/cached-node-modules/action.yml b/.github/actions/cached-node-modules/action.yml index 83bdfa7b5c..465a38fc2f 100644 --- a/.github/actions/cached-node-modules/action.yml +++ b/.github/actions/cached-node-modules/action.yml @@ -44,7 +44,6 @@ runs: npm run build -w packages/tracer & \ npm run build -w packages/metrics & \ npm run build -w packages/parameters & \ - npm run build -w packages/jmespath & \ npm run build -w packages/idempotency & \ npm run build -w packages/batch & \ npm run build -w packages/testing From 31a6effb719be5c6e0c5ccf7c55dac5e82de5baf Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 16 Apr 2024 13:00:45 +0200 Subject: [PATCH 6/9] chore: update layer setup --- layers/src/layer-publisher-stack.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index cbbdebc105..b4fb24f19f 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -69,7 +69,6 @@ export class LayerPublisherStack extends Stack { 'parameters', 'idempotency', 'batch', - 'jmespath', ]; // These files are relative to the tmp folder From 2ac03d82d5f57c0b35235d8b4995eb3ce1f074c2 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 16 Apr 2024 14:43:15 +0200 Subject: [PATCH 7/9] refactor(jmespath): rename jmespath parsing options type --- packages/idempotency/src/IdempotencyConfig.ts | 4 +++ packages/jmespath/src/ParsedResult.ts | 4 +-- packages/jmespath/src/TreeInterpreter.ts | 4 +-- packages/jmespath/src/envelopes.ts | 4 +-- packages/jmespath/src/search.ts | 4 +-- packages/jmespath/src/types.ts | 26 +++++++------------ 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/idempotency/src/IdempotencyConfig.ts b/packages/idempotency/src/IdempotencyConfig.ts index 3d15757242..7edc20e1f7 100644 --- a/packages/idempotency/src/IdempotencyConfig.ts +++ b/packages/idempotency/src/IdempotencyConfig.ts @@ -25,7 +25,11 @@ class IdempotencyConfig { */ public hashFunction: string; /** + * Options for parsing JMESPath expressions. * + * By default, you can use any of the {@link https://jmespath.org/specification.html | JMESPath built-in functions} as well as the + * {@link https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_jmespath.PowertoolsFunctions.PowertoolsFunctions.html | custom functions provided} + * by the `@aws-lambda-powertools/jmespath` package. */ public jmesPathOptions: ParsingOptions; /** diff --git a/packages/jmespath/src/ParsedResult.ts b/packages/jmespath/src/ParsedResult.ts index 63610bff31..4d6733dbcc 100644 --- a/packages/jmespath/src/ParsedResult.ts +++ b/packages/jmespath/src/ParsedResult.ts @@ -5,7 +5,7 @@ import { UnknownFunctionError, VariadicArityError, } from './errors.js'; -import type { Node, ParsingOptions, JSONObject } from './types.js'; +import type { Node, JMESPathParsingOptions, JSONObject } from './types.js'; class ParsedResult { public expression: string; @@ -22,7 +22,7 @@ class ParsedResult { * @param value The JSON value to search * @param options The parsing options to use */ - public search(value: JSONObject, options?: ParsingOptions): unknown { + public search(value: JSONObject, options?: JMESPathParsingOptions): unknown { const interpreter = new TreeInterpreter(options); try { diff --git a/packages/jmespath/src/TreeInterpreter.ts b/packages/jmespath/src/TreeInterpreter.ts index 28d2c531bc..ee2292bd99 100644 --- a/packages/jmespath/src/TreeInterpreter.ts +++ b/packages/jmespath/src/TreeInterpreter.ts @@ -12,7 +12,7 @@ import { } from './errors.js'; import { Expression } from './Expression.js'; import { Functions } from './Functions.js'; -import type { Node, TreeInterpreterOptions, JSONObject } from './types.js'; +import type { Node, JMESPathParsingOptions, JSONObject } from './types.js'; import { isTruthy, sliceArray } from './utils.js'; /** @@ -30,7 +30,7 @@ class TreeInterpreter { /** * @param options The options to use for the interpreter. */ - public constructor(options?: TreeInterpreterOptions) { + public constructor(options?: JMESPathParsingOptions) { if (options?.customFunctions) { this.#functions = options.customFunctions; } else { diff --git a/packages/jmespath/src/envelopes.ts b/packages/jmespath/src/envelopes.ts index 84cf06c383..2fa2607c85 100644 --- a/packages/jmespath/src/envelopes.ts +++ b/packages/jmespath/src/envelopes.ts @@ -1,6 +1,6 @@ import { search } from './search.js'; import { PowertoolsFunctions } from './PowertoolsFunctions.js'; -import type { ParsingOptions, JSONObject } from './types.js'; +import type { JMESPathParsingOptions, JSONObject } from './types.js'; /** * Searches and extracts data using JMESPath @@ -57,7 +57,7 @@ import type { ParsingOptions, JSONObject } from './types.js'; const extractDataFromEnvelope = ( data: JSONObject, envelope: string, - options?: ParsingOptions + options?: JMESPathParsingOptions ): T => { if (!options) { options = { customFunctions: new PowertoolsFunctions() }; diff --git a/packages/jmespath/src/search.ts b/packages/jmespath/src/search.ts index 8f53775fa5..44afcd61c4 100644 --- a/packages/jmespath/src/search.ts +++ b/packages/jmespath/src/search.ts @@ -1,5 +1,5 @@ import { Parser } from './Parser.js'; -import type { ParsingOptions, JSONObject } from './types.js'; +import type { JMESPathParsingOptions, JSONObject } from './types.js'; const parser = new Parser(); @@ -52,7 +52,7 @@ const parser = new Parser(); const search = ( expression: string, data: JSONObject, - options?: ParsingOptions + options?: JMESPathParsingOptions ): unknown => { return parser.parse(expression).search(data, options); }; diff --git a/packages/jmespath/src/types.ts b/packages/jmespath/src/types.ts index 07eef2fb33..19d102e6b3 100644 --- a/packages/jmespath/src/types.ts +++ b/packages/jmespath/src/types.ts @@ -24,19 +24,6 @@ type Node = { value?: JSONValue; }; -/** - * Options for the tree interpreter. - */ -type TreeInterpreterOptions = { - /** - * 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; -}; - /** * Options for parsing. * @@ -57,7 +44,15 @@ type TreeInterpreterOptions = { * console.log(result); // { a: 1 } * ``` */ -type ParsingOptions = TreeInterpreterOptions; +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. @@ -103,8 +98,7 @@ export type { FunctionSignatureDecorator, FunctionSignatureOptions, Node, - ParsingOptions, + JMESPathParsingOptions, Token, - TreeInterpreterOptions, JSONObject, }; From 0c74901e95b0e86721cdd54753643da5fe3ac2b2 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 16 Apr 2024 14:46:19 +0200 Subject: [PATCH 8/9] chore: updated occurrences --- packages/idempotency/src/IdempotencyConfig.ts | 4 ++-- packages/idempotency/src/persistence/BasePersistenceLayer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/idempotency/src/IdempotencyConfig.ts b/packages/idempotency/src/IdempotencyConfig.ts index 7edc20e1f7..0a89a4af4c 100644 --- a/packages/idempotency/src/IdempotencyConfig.ts +++ b/packages/idempotency/src/IdempotencyConfig.ts @@ -1,7 +1,7 @@ import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js'; import type { Context } from 'aws-lambda'; import type { IdempotencyConfigOptions } from './types/IdempotencyOptions.js'; -import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types'; +import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types'; import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions'; /** @@ -31,7 +31,7 @@ class IdempotencyConfig { * {@link https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_jmespath.PowertoolsFunctions.PowertoolsFunctions.html | custom functions provided} * by the `@aws-lambda-powertools/jmespath` package. */ - public jmesPathOptions: ParsingOptions; + public jmesPathOptions: JMESPathParsingOptions; /** * The lambda context object. */ diff --git a/packages/idempotency/src/persistence/BasePersistenceLayer.ts b/packages/idempotency/src/persistence/BasePersistenceLayer.ts index f02cbe5b8f..1456d70f12 100644 --- a/packages/idempotency/src/persistence/BasePersistenceLayer.ts +++ b/packages/idempotency/src/persistence/BasePersistenceLayer.ts @@ -1,6 +1,6 @@ import { createHash, Hash } from 'node:crypto'; import { search } from '@aws-lambda-powertools/jmespath'; -import type { ParsingOptions } from '@aws-lambda-powertools/jmespath/types'; +import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types'; import type { BasePersistenceLayerOptions, BasePersistenceLayerInterface, @@ -37,7 +37,7 @@ abstract class BasePersistenceLayer implements BasePersistenceLayerInterface { private throwOnNoIdempotencyKey = false; private useLocalCache = false; private validationKeyJmesPath?: string; - #jmesPathOptions?: ParsingOptions; + #jmesPathOptions?: JMESPathParsingOptions; public constructor() { this.envVarsService = new EnvironmentVariablesService(); From 785bcad9f9f34bbb9192f57f441a16f523f62453 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 16 Apr 2024 17:55:46 +0200 Subject: [PATCH 9/9] chore: merge conflicts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66b46f7f4e..ea87efdd6d 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A suite of utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more.", "workspaces": [ "packages/commons", + "packages/jmespath", "packages/logger", "packages/metrics", "packages/tracer", @@ -11,7 +12,6 @@ "packages/idempotency", "packages/batch", "packages/testing", - "packages/jmespath", "packages/parser", "docs/snippets", "layers",