Skip to content

Commit 564e71c

Browse files
dreamorosisvozza
andauthored
chore(maintenance): general refactoring (#4905)
Co-authored-by: Stefano Vozza <[email protected]>
1 parent d7c1a40 commit 564e71c

32 files changed

Lines changed: 1958 additions & 1984 deletions

examples/app/functions/commons/powertools/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* We have single entry point for all the powertools modules so that functions that need only one
33
* can bundle only that one that they need and keep the bundle size small.
44
*/
5-
import { logger } from './logger.js';
6-
import { metrics } from './metrics.js';
7-
import { tracer } from './tracer.js';
8-
9-
// We export all three modules for those functions who need to use all of them
10-
export { logger, metrics, tracer };
5+
export { logger } from './logger.js';
6+
export { metrics } from './metrics.js';
7+
export { tracer } from './tracer.js';

layers/src/layer-publisher-stack.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ export class LayerPublisherStack extends Stack {
122122

123123
if (buildFromLocal) {
124124
for (const util of utilities) {
125-
// Build latest version of the package
126-
buildCommands.push(`npm run build -w packages/${util}`);
127-
// Pack the package to a .tgz file
128-
buildCommands.push(`npm pack -w packages/${util}`);
129-
// Move the .tgz file to the tmp folder
130125
buildCommands.push(
126+
// Build latest version of the package
127+
`npm run build -w packages/${util}`,
128+
// Pack the package to a .tgz file
129+
`npm pack -w packages/${util}`,
130+
// Move the .tgz file to the tmp folder
131131
`mv aws-lambda-powertools-${util}-*.tgz ${tmpBuildDir}`
132132
);
133133
}

layers/tests/e2e/layerPublisher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Layers E2E tests', () => {
107107
await testStack.deploy();
108108

109109
// Invoke the lambda function once for each output format and collect the logs
110-
for await (const outputFormat of cases) {
110+
for (const outputFormat of cases) {
111111
invocationLogsMap.set(
112112
outputFormat,
113113
await invokeFunctionOnce({

packages/commons/src/unmarshallDynamoDB.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const typeHandlers: Record<string, (value: any) => unknown> = {
1414
B: (value) => value,
1515
BS: (value) => new Set(value),
1616
SS: (value) => new Set(value),
17-
BOOL: (value) => Boolean(value),
17+
BOOL: Boolean,
1818
N: (value) => convertNumber(value),
1919
NS: (value) => new Set((value as Array<string>).map(convertNumber)),
2020
L: (value) => (value as Array<AttributeValue>).map(convertAttributeValue),

packages/event-handler/src/appsync-events/RouteHandlerRegistry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ class RouteHandlerRegistry {
151151
* @param path - The path to be converted to a regex string
152152
*/
153153
static pathToRegexString(path: string): string {
154-
const escapedPath = path.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
155-
return `^${escapedPath.replace(/\\\*/g, '.*')}$`;
154+
const escapedPath = path.replace(
155+
/([.*+?^=!:${}()|[\]/\\])/g,
156+
String.raw`\$1`
157+
);
158+
return `^${escapedPath.replaceAll('\\*', '.*')}$`; // NOSONAR - Need literal backslash to match escaped asterisks
156159
}
157160
}
158161

packages/event-handler/tests/helpers/factories.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
const onPublishEventFactory = (
2-
events: Array<{ payload: unknown; id: string }> = [
3-
{
4-
payload: {
5-
event_1: 'data_1',
6-
},
7-
id: '5f7dfbd1-b8ff-4c20-924e-23b42db467a0',
1+
const defaultChannel = {
2+
path: '/request/channel',
3+
segments: ['request', 'channel'],
4+
};
5+
6+
const defaultEvents = [
7+
{
8+
payload: {
9+
event_1: 'data_1',
810
},
9-
{
10-
payload: {
11-
event_2: 'data_2',
12-
},
13-
id: 'ababdf65-a3e6-4c1d-acd3-87466eab433c',
11+
id: '5f7dfbd1-b8ff-4c20-924e-23b42db467a0',
12+
},
13+
{
14+
payload: {
15+
event_2: 'data_2',
1416
},
15-
{
16-
payload: {
17-
event_3: 'data_3',
18-
},
19-
id: '8bb2983a-0967-45a0-8243-0aeb8c83d80e',
17+
id: 'ababdf65-a3e6-4c1d-acd3-87466eab433c',
18+
},
19+
{
20+
payload: {
21+
event_3: 'data_3',
2022
},
21-
],
22-
channel = {
23-
path: '/request/channel',
24-
segments: ['request', 'channel'],
25-
}
23+
id: '8bb2983a-0967-45a0-8243-0aeb8c83d80e',
24+
},
25+
];
26+
27+
const onPublishEventFactory = (
28+
events: Array<{ payload: unknown; id: string }> = defaultEvents,
29+
channel = defaultChannel
2630
) => ({
2731
identity: null,
2832
result: null,
@@ -46,12 +50,7 @@ const onPublishEventFactory = (
4650
events,
4751
});
4852

49-
const onSubscribeEventFactory = (
50-
channel = {
51-
path: '/request/channel',
52-
segments: ['request', 'channel'],
53-
}
54-
) => ({
53+
const onSubscribeEventFactory = (channel = defaultChannel) => ({
5554
identity: null,
5655
result: null,
5756
request: {

packages/idempotency/src/makeIdempotent.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function makeIdempotent<Func extends AnyFunction>(
126126
options: ItempotentFunctionOptions<Parameters<Func>>
127127
): (...args: Parameters<Func>) => ReturnType<Func> {
128128
const { persistenceStore, config, keyPrefix } = options;
129-
const idempotencyConfig = config ? config : new IdempotencyConfig({});
129+
const idempotencyConfig = config ?? new IdempotencyConfig({});
130130

131131
if (!idempotencyConfig.isEnabled()) return fn;
132132

@@ -140,12 +140,10 @@ function makeIdempotent<Func extends AnyFunction>(
140140
args[1]?.lambdaContext || args[1]
141141
);
142142
functionPayloadToBeHashed = args[0];
143+
} else if (isOptionsWithDataIndexArgument(options)) {
144+
functionPayloadToBeHashed = args[options.dataIndexArgument];
143145
} else {
144-
if (isOptionsWithDataIndexArgument(options)) {
145-
functionPayloadToBeHashed = args[options.dataIndexArgument];
146-
} else {
147-
functionPayloadToBeHashed = args[0];
148-
}
146+
functionPayloadToBeHashed = args[0];
149147
}
150148

151149
const isReplay = args[1]?.durableExecutionMode === 'ReplayMode';

packages/idempotency/src/middleware/makeHandlerIdempotent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ const makeHandlerIdempotent = (
113113
* @param request - The Middy request object
114114
*/
115115
const before = (request: MiddyLikeRequest): unknown => {
116-
const idempotencyConfig = options.config
117-
? options.config
118-
: new IdempotencyConfig({});
116+
const idempotencyConfig = options.config ?? new IdempotencyConfig({});
119117
const persistenceStore = options.persistenceStore;
120118
const keyPrefix = options.keyPrefix;
121119
persistenceStore.configure({

packages/idempotency/src/persistence/DynamoDBPersistenceLayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class DynamoDBPersistenceLayer extends BasePersistenceLayer {
155155

156156
if (this.isPayloadValidationEnabled() && record.payloadHash !== undefined) {
157157
item[this.validationKeyAttr] = {
158-
S: record.payloadHash as string,
158+
S: record.payloadHash,
159159
};
160160
}
161161

packages/idempotency/tests/e2e/makeIdempotent.test.FunctionCode.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import { Logger } from '@aws-lambda-powertools/logger';
23
import type { Context } from 'aws-lambda';
34
import { IdempotencyConfig } from '../../src/IdempotencyConfig.js';
@@ -31,7 +32,8 @@ const logger = new Logger();
3132
*/
3233
const idempotencyConfig = new IdempotencyConfig({});
3334
const processIdempotently = makeIdempotent(
34-
(record: Record<string, unknown>): string => {
35+
async (record: Record<string, unknown>): Promise<string> => {
36+
await setTimeout(0);
3537
logger.info('Got test event', { record });
3638

3739
return `Processing done: ${record.foo}`;
@@ -62,7 +64,11 @@ const idempotencyConfigWithSelection = new IdempotencyConfig({
6264
payloadValidationJmesPath: 'foo',
6365
});
6466
const processIdempotentlyCustomized = makeIdempotent(
65-
(baz: number, record: Record<string, unknown>): Record<string, unknown> => {
67+
async (
68+
baz: number,
69+
record: Record<string, unknown>
70+
): Promise<Record<string, unknown>> => {
71+
await setTimeout(0);
6672
logger.info('Got test event', { baz, record });
6773

6874
return record;

0 commit comments

Comments
 (0)