@beesolve/sqs-handler 0.1.2 → 0.1.4

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/dist/cdk.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // packages/sqs-handler/cdk.ts
2
+ import { SqsWithDlq } from "@beesolve/cdk-constructs";
2
3
  import { Duration } from "aws-cdk-lib";
3
4
  import { Architecture, Runtime } from "aws-cdk-lib/aws-lambda";
4
5
  import {
package/dist/index.js CHANGED
@@ -11,17 +11,17 @@ function createSqsHandlers(props) {
11
11
  for (const { body, messageId } of event.Records) {
12
12
  try {
13
13
  const result = v.safeParse(v.pipe(v.string(), v.parseJson(), v.object({
14
- fName: v.picklist(Object.keys(props.functions)),
15
- fArgs: v.array(v.any())
14
+ fn: v.picklist(Object.keys(props.functions)),
15
+ args: v.array(v.any())
16
16
  })), body);
17
17
  if (!result.success)
18
18
  throw new Error(`Wrong message format: ${JSON.stringify(v.flatten(result.issues), null, 2)}`);
19
- const { fName, fArgs } = result.output;
19
+ const { fn, args } = result.output;
20
20
  console.info({
21
- function: fName,
22
- arguments: JSON.stringify(fArgs, null, 2)
21
+ function: fn,
22
+ arguments: args
23
23
  });
24
- await props.functions[fName]?.(...fArgs.map((args) => decodeFromStringifiable(args)));
24
+ await props.functions[fn]?.(...args.map((args2) => decodeFromStringifiable(args2)));
25
25
  } catch (error) {
26
26
  console.error(error);
27
27
  batchItemFailures.push({ itemIdentifier: messageId });
@@ -31,20 +31,20 @@ function createSqsHandlers(props) {
31
31
  };
32
32
  const functions = Object.entries(props.functions).reduce((result, [functionName]) => ({
33
33
  ...result,
34
- [functionName](...args) {
34
+ async[functionName](...args) {
35
35
  const originalFunction = props.functions[functionName];
36
36
  if (originalFunction == null)
37
37
  throw Error(`Cannot invoke "${functionName}". Make sure the function is defined.`);
38
38
  const functionArgs = args.slice(0, originalFunction.length);
39
39
  const fifoOptions = args[originalFunction.length];
40
40
  if (props.localInvocation) {
41
- originalFunction(...functionArgs);
41
+ await originalFunction(...functionArgs);
42
42
  } else {
43
- props.sqsClient.send(new SendMessageCommand({
43
+ await props.sqsClient.send(new SendMessageCommand({
44
44
  QueueUrl: props.queueUrl,
45
45
  MessageBody: JSON.stringify({
46
- fName: functionName,
47
- fArgs: functionArgs.map((args2) => encodeToStringifiable(args2))
46
+ fn: functionName,
47
+ args: functionArgs.map((args2) => encodeToStringifiable(args2))
48
48
  }),
49
49
  MessageDeduplicationId: fifoOptions?.deduplicationId,
50
50
  MessageGroupId: fifoOptions?.groupId
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@beesolve/sqs-handler",
3
3
  "description": "",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"