Skip to content

Commit e2f68c3

Browse files
authored
Merge branch 'main' into improv/commons/typeutils
2 parents 0f445ca + b012173 commit e2f68c3

File tree

7 files changed

+574
-5
lines changed

7 files changed

+574
-5
lines changed

docs/core/tracer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The library has three optional settings. You can set them as environment variabl
5555
| **Capture Errors** | Defines whether functions errors are serialized as metadata | `POWERTOOLS_TRACER_CAPTURE_ERROR` | `true` | `true` or `false` | `false` | N/A |
5656

5757
!!! note
58-
Before your use this utility, your AWS Lambda function must have [Active Tracing enabled](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html) as well as [have permissions](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html#services-xray-permissions) to send traces to AWS X-Ray
58+
Before you use this utility, your AWS Lambda function must have [Active Tracing enabled](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html) as well as [have permissions](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html#services-xray-permissions) to send traces to AWS X-Ray
5959

6060
#### Example using AWS Serverless Application Model (SAM)
6161

docs/upgrade.md

+52-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ V2 is focused on official support for ESM (ECMAScript modules). We've made other
1010
### Quick summary
1111

1212
| Area | Change | Code change required |
13-
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------- |
13+
| --------------------- |--------------------------------------------------------------------------------------------------------------------------------| -------------------- |
1414
| **ESM support** | Added ESM support via dual CommonJS and ESM bundling, enabling top-level `await` and tree-shaking. | - |
1515
| **Middy.js** | Updated import path for Middy.js middlewares to leverage subpath exports - i.e. `@aws-lambda-powertools/tracer/middleware`. | Yes |
1616
| **Types imports** | Updated import path for TypeScript types to leverage subpath exports - i.e. `@aws-lambda-powertools/logger/types`. | Yes |
1717
| **Logger** | Changed [log sampling](./core/logger.md#sampling-logs) to dynamically switch log level to `DEBUG` on a percentage of requests. | - |
1818
| **Logger** | Updated [custom log formatter](#custom-log-formatter) to include standard as well as persistent keys. | Yes |
19+
| **Logger** | Removed `ContextExamples` from `@aws-lambda-powertools/commons` package. | Yes |
1920
| **Logger and Tracer** | Removed deprecated `createLogger` and `createTracer` helper functions in favor of direct instantiation. | Yes |
2021

2122

@@ -280,6 +281,56 @@ In v2, you have more control over **standard** (`attributes`) and [**custom keys
280281
2. `LogItem` is the new return object instead of a plain object.
281282
3. If you prefer adding at the initialization, use: <br/><br/> **`LogItem({persistentAttributes: additionalLogAttributes, attributes: baseAttributes})`**
282283

284+
### ContextExamples for testing
285+
286+
In v1, we have provided a `ContextExamples` object to help you with testing.
287+
288+
In v2, we have removed the `ContextExamples` from the `@aws-lambda-powertools/commons` package, so you need to create it in your tests:
289+
290+
=== "Before"
291+
292+
```typescript
293+
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';
294+
295+
describe('MyUnitTest', () => {
296+
test('Lambda invoked successfully', async () => {
297+
const testEvent = { test: 'test' };
298+
await handler(testEvent, dummyContext);
299+
});
300+
});
301+
```
302+
303+
=== "After"
304+
305+
```typescript
306+
declare const handler: (event: unknown, context: unknown) => Promise<void>;
307+
308+
const context = {
309+
callbackWaitsForEmptyEventLoop: true,
310+
functionVersion: '$LATEST',
311+
functionName: 'foo-bar-function',
312+
memoryLimitInMB: '128',
313+
logGroupName: '/aws/lambda/foo-bar-function-123456abcdef',
314+
logStreamName: '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456',
315+
invokedFunctionArn:
316+
'arn:aws:lambda:eu-west-1:123456789012:function:foo-bar-function',
317+
awsRequestId: 'c6af9ac6-7b61-11e6-9a41-93e812345678',
318+
getRemainingTimeInMillis: () => 1234,
319+
done: () => console.log('Done!'),
320+
fail: () => console.log('Failed!'),
321+
succeed: () => console.log('Succeeded!'),
322+
};
323+
324+
describe('MyUnitTest', () => {
325+
test('Lambda invoked successfully', async () => {
326+
const testEvent = { test: 'test' };
327+
await handler(testEvent, context);
328+
});
329+
});
330+
```
331+
332+
333+
283334
## Helper functions
284335

285336
We removed the deprecated `createLogger` and `createTracer` heper functions.

packages/jmespath/src/Functions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is a placeholder for the real class. The actual implementation will be added in a subsequent PR.
2+
export class Functions {
3+
public iAmAPlaceholder = true;
4+
}

packages/jmespath/src/constants.ts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* The binding powers for the various tokens in the JMESPath grammar.
3+
*
4+
* The binding powers are used to determine the order of operations for
5+
* the parser. The higher the binding power, the more tightly the token
6+
* binds to its arguments.
7+
*/
8+
const BINDING_POWER = {
9+
eof: 0,
10+
unquoted_identifier: 0,
11+
quoted_identifier: 0,
12+
literal: 0,
13+
rbracket: 0,
14+
rparen: 0,
15+
comma: 0,
16+
rbrace: 0,
17+
number: 0,
18+
current: 0,
19+
expref: 0,
20+
colon: 0,
21+
pipe: 1,
22+
or: 2,
23+
and: 3,
24+
eq: 5,
25+
gt: 5,
26+
lt: 5,
27+
gte: 5,
28+
lte: 5,
29+
ne: 5,
30+
flatten: 9,
31+
// Everything above stops a projection.
32+
star: 20,
33+
filter: 21,
34+
dot: 40,
35+
not: 45,
36+
lbrace: 50,
37+
lbracket: 55,
38+
lparen: 60,
39+
} as const;
40+
41+
/**
42+
* The set of ASCII lowercase letters allowed in JMESPath identifiers.
43+
*/
44+
const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
45+
/**
46+
* The set of ASCII uppercase letters allowed in JMESPath identifiers.
47+
*/
48+
const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
49+
/**
50+
* The set of ASCII letters allowed in JMESPath identifiers.
51+
*/
52+
const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE;
53+
/**
54+
* The set of ASCII digits allowed in JMESPath identifiers.
55+
*/
56+
const DIGITS = '0123456789';
57+
/**
58+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
59+
*/
60+
const START_IDENTIFIER = new Set(ASCII_LETTERS + '_');
61+
/**
62+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
63+
*/
64+
const VALID_IDENTIFIER = new Set(ASCII_LETTERS + DIGITS + '_');
65+
/**
66+
* The set of ASCII digits allowed in JMESPath identifiers.
67+
*/
68+
const VALID_NUMBER = new Set(DIGITS);
69+
/**
70+
* The set of ASCII whitespace characters allowed in JMESPath identifiers.
71+
*/
72+
const WHITESPACE = new Set(' \t\n\r');
73+
/**
74+
* The set of simple tokens in the JMESPath grammar.
75+
*/
76+
const SIMPLE_TOKENS: Map<string, keyof typeof BINDING_POWER> = new Map([
77+
['.', 'dot'],
78+
['*', 'star'],
79+
[':', 'colon'],
80+
[']', 'rbracket'],
81+
[',', 'comma'],
82+
[':', 'colon'],
83+
['@', 'current'],
84+
['(', 'lparen'],
85+
[')', 'rparen'],
86+
['{', 'lbrace'],
87+
['}', 'rbrace'],
88+
]);
89+
90+
export {
91+
BINDING_POWER,
92+
SIMPLE_TOKENS,
93+
START_IDENTIFIER,
94+
VALID_IDENTIFIER,
95+
VALID_NUMBER,
96+
WHITESPACE,
97+
};

0 commit comments

Comments
 (0)