skuba 12.1.0-hoist-less-20250722131939 → 12.1.0-main-20250810101347
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.
- package/README.md +1 -2
- package/config/tsconfig.json +3 -2
- package/lib/cli/build/tsc.d.ts +5 -1
- package/lib/cli/build/tsc.js +12 -0
- package/lib/cli/build/tsc.js.map +3 -3
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.d.ts +2 -0
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js +35 -0
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js.map +7 -0
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.d.ts +4 -0
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js +162 -0
- package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js.map +7 -0
- package/lib/cli/node/index.js +8 -2
- package/lib/cli/node/index.js.map +2 -2
- package/lib/cli/start/index.js +8 -2
- package/lib/cli/start/index.js.map +2 -2
- package/lib/cli/test/index.d.ts +1 -1
- package/lib/cli/test/index.js +18 -4
- package/lib/cli/test/index.js.map +2 -2
- package/lib/utils/args.d.ts +2 -0
- package/lib/utils/args.js +5 -0
- package/lib/utils/args.js.map +2 -2
- package/package.json +14 -15
- package/template/base/_pnpm-workspace.yaml +1 -0
- package/template/express-rest-api/package.json +4 -4
- package/template/express-rest-api/src/listen.ts +6 -0
- package/template/greeter/package.json +2 -2
- package/template/koa-rest-api/package.json +9 -9
- package/template/koa-rest-api/src/framework/server.test.ts +0 -1
- package/template/koa-rest-api/src/listen.ts +6 -0
- package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +16 -2
- package/template/lambda-sqs-worker-cdk/infra/appStack.ts +5 -1
- package/template/lambda-sqs-worker-cdk/infra/config.ts +4 -1
- package/template/lambda-sqs-worker-cdk/package.json +5 -5
- package/template/lambda-sqs-worker-cdk/src/app.test.ts +88 -48
- package/template/lambda-sqs-worker-cdk/src/app.ts +7 -9
- package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +8 -3
- package/template/lambda-sqs-worker-cdk/src/framework/handler.ts +38 -5
- package/template/lambda-sqs-worker-cdk/src/framework/logging.ts +11 -3
- package/template/lambda-sqs-worker-cdk/src/testing/handler.ts +4 -1
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Context as LambdaContext,
|
|
3
|
+
SQSBatchItemFailure,
|
|
4
|
+
SQSBatchResponse,
|
|
5
|
+
SQSEvent,
|
|
6
|
+
SQSRecord,
|
|
7
|
+
} from 'aws-lambda';
|
|
2
8
|
import { datadog } from 'datadog-lambda-js';
|
|
3
9
|
|
|
4
10
|
import { config } from 'src/config.js';
|
|
5
|
-
import { logger,
|
|
11
|
+
import { lambdaContext, logger, recordContext } from 'src/framework/logging.js';
|
|
6
12
|
|
|
7
13
|
type Handler<Event, Output> = (
|
|
8
14
|
event: Event,
|
|
@@ -20,15 +26,15 @@ const withDatadog = <Event, Output = unknown>(
|
|
|
20
26
|
// istanbul ignore next
|
|
21
27
|
config.metrics ? (datadog(fn) as Handler<Event, Output>) : fn;
|
|
22
28
|
|
|
23
|
-
export const createHandler = <Event, Output = unknown>(
|
|
29
|
+
export const createHandler = <Event extends SQSEvent, Output = unknown>(
|
|
24
30
|
fn: (event: Event, ctx: LambdaContext) => Promise<Output>,
|
|
25
31
|
) =>
|
|
26
32
|
withDatadog<Event>((event, ctx) =>
|
|
27
|
-
|
|
33
|
+
lambdaContext.run({ awsRequestId: ctx.awsRequestId }, async () => {
|
|
28
34
|
try {
|
|
29
35
|
const output = await fn(event, ctx);
|
|
30
36
|
|
|
31
|
-
logger.debug('Function
|
|
37
|
+
logger.debug({ output }, 'Function completed');
|
|
32
38
|
|
|
33
39
|
return output;
|
|
34
40
|
} catch (err) {
|
|
@@ -38,3 +44,30 @@ export const createHandler = <Event, Output = unknown>(
|
|
|
38
44
|
}
|
|
39
45
|
}),
|
|
40
46
|
);
|
|
47
|
+
|
|
48
|
+
export const createBatchSQSHandler =
|
|
49
|
+
(
|
|
50
|
+
fn: (record: SQSRecord, ctx: LambdaContext) => Promise<unknown>,
|
|
51
|
+
): Handler<SQSEvent, SQSBatchResponse> =>
|
|
52
|
+
async (event, ctx) => {
|
|
53
|
+
const processRecord = (
|
|
54
|
+
record: SQSRecord,
|
|
55
|
+
): Promise<SQSBatchItemFailure | undefined> =>
|
|
56
|
+
recordContext.run({ sqsMessageId: record.messageId }, async () => {
|
|
57
|
+
try {
|
|
58
|
+
await fn(record, ctx);
|
|
59
|
+
return;
|
|
60
|
+
} catch (err) {
|
|
61
|
+
logger.error({ err }, 'Processing record failed');
|
|
62
|
+
return {
|
|
63
|
+
itemIdentifier: record.messageId,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const results = await Promise.all(event.Records.map(processRecord));
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
batchItemFailures: results.filter((item) => item !== undefined),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -4,11 +4,16 @@ import createLogger, { createDestination } from '@seek/logger';
|
|
|
4
4
|
|
|
5
5
|
import { config } from 'src/config.js';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface LambdaContext {
|
|
8
8
|
awsRequestId: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface RecordContext {
|
|
12
|
+
sqsMessageId: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const lambdaContext = new AsyncLocalStorage<LambdaContext>();
|
|
16
|
+
export const recordContext = new AsyncLocalStorage<RecordContext>();
|
|
12
17
|
|
|
13
18
|
const { destination, stdoutMock } = createDestination({
|
|
14
19
|
mock: config.environment === 'test' && {
|
|
@@ -27,7 +32,10 @@ export const logger = createLogger(
|
|
|
27
32
|
|
|
28
33
|
level: config.logLevel,
|
|
29
34
|
|
|
30
|
-
mixin: () => ({
|
|
35
|
+
mixin: () => ({
|
|
36
|
+
...lambdaContext.getStore(),
|
|
37
|
+
...recordContext.getStore(),
|
|
38
|
+
}),
|
|
31
39
|
|
|
32
40
|
name: config.name,
|
|
33
41
|
|