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.
Files changed (39) hide show
  1. package/README.md +1 -2
  2. package/config/tsconfig.json +3 -2
  3. package/lib/cli/build/tsc.d.ts +5 -1
  4. package/lib/cli/build/tsc.js +12 -0
  5. package/lib/cli/build/tsc.js.map +3 -3
  6. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.d.ts +2 -0
  7. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js +35 -0
  8. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js.map +7 -0
  9. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.d.ts +4 -0
  10. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js +162 -0
  11. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js.map +7 -0
  12. package/lib/cli/node/index.js +8 -2
  13. package/lib/cli/node/index.js.map +2 -2
  14. package/lib/cli/start/index.js +8 -2
  15. package/lib/cli/start/index.js.map +2 -2
  16. package/lib/cli/test/index.d.ts +1 -1
  17. package/lib/cli/test/index.js +18 -4
  18. package/lib/cli/test/index.js.map +2 -2
  19. package/lib/utils/args.d.ts +2 -0
  20. package/lib/utils/args.js +5 -0
  21. package/lib/utils/args.js.map +2 -2
  22. package/package.json +14 -15
  23. package/template/base/_pnpm-workspace.yaml +1 -0
  24. package/template/express-rest-api/package.json +4 -4
  25. package/template/express-rest-api/src/listen.ts +6 -0
  26. package/template/greeter/package.json +2 -2
  27. package/template/koa-rest-api/package.json +9 -9
  28. package/template/koa-rest-api/src/framework/server.test.ts +0 -1
  29. package/template/koa-rest-api/src/listen.ts +6 -0
  30. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +16 -2
  31. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +5 -1
  32. package/template/lambda-sqs-worker-cdk/infra/config.ts +4 -1
  33. package/template/lambda-sqs-worker-cdk/package.json +5 -5
  34. package/template/lambda-sqs-worker-cdk/src/app.test.ts +88 -48
  35. package/template/lambda-sqs-worker-cdk/src/app.ts +7 -9
  36. package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +8 -3
  37. package/template/lambda-sqs-worker-cdk/src/framework/handler.ts +38 -5
  38. package/template/lambda-sqs-worker-cdk/src/framework/logging.ts +11 -3
  39. package/template/lambda-sqs-worker-cdk/src/testing/handler.ts +4 -1
@@ -1,8 +1,14 @@
1
- import type { Context as LambdaContext } from 'aws-lambda';
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, loggerContext } from 'src/framework/logging.js';
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
- loggerContext.run({ awsRequestId: ctx.awsRequestId }, async () => {
33
+ lambdaContext.run({ awsRequestId: ctx.awsRequestId }, async () => {
28
34
  try {
29
35
  const output = await fn(event, ctx);
30
36
 
31
- logger.debug('Function succeeded');
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 LoggerContext {
7
+ interface LambdaContext {
8
8
  awsRequestId: string;
9
9
  }
10
10
 
11
- export const loggerContext = new AsyncLocalStorage<LoggerContext>();
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: () => ({ ...loggerContext.getStore() }),
35
+ mixin: () => ({
36
+ ...lambdaContext.getStore(),
37
+ ...recordContext.getStore(),
38
+ }),
31
39
 
32
40
  name: config.name,
33
41
 
@@ -9,5 +9,8 @@ export const createCtx = () =>
9
9
 
10
10
  export const createSqsEvent = (bodies: string[]) =>
11
11
  ({
12
- Records: bodies.map((body) => ({ body })),
12
+ Records: bodies.map((body) => ({
13
+ body,
14
+ messageId: chance.guid({ version: 4 }),
15
+ })),
13
16
  }) as SQSEvent;