From 559134bc85f61a09b70bac2fafecc7ed49889f7e Mon Sep 17 00:00:00 2001 From: Ab C <219340+abdala@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:26:02 +0100 Subject: [PATCH] Add types to SNS plugin --- dtc-aws-plugin/src/sns-plugin.ts | 22 +++++++++++++--------- tsconfig.json | 1 - 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dtc-aws-plugin/src/sns-plugin.ts b/dtc-aws-plugin/src/sns-plugin.ts index 29162cf..3b96fcc 100644 --- a/dtc-aws-plugin/src/sns-plugin.ts +++ b/dtc-aws-plugin/src/sns-plugin.ts @@ -1,18 +1,22 @@ -import {isRecord} from '@cgauge/dtc' -import {MessageAttributeValue, SNS} from '@aws-sdk/client-sns' +import {SNS} from '@aws-sdk/client-sns' +import { info } from '@cgauge/dtc' +import {is, unknown, record, optional, union, diff} from 'type-assurance' -type SnsCall = { - topic: string - message: Record - messageAttributes?: Record +const SnsCall = { + topic: String, + message: record(String, unknown), + messageAttributes: optional(record(String, { + DataType: union(String, undefined), + StringValue: optional(String), + })) } -const isSnsAct = (v: unknown): v is SnsCall => isRecord(v) && 'topic' in v && 'message' in v - const sns = new SNS({}) export const act = async (args: unknown) => { - if (!isSnsAct(args)) { + if (!is(args, SnsCall)) { + const mismatch = diff(args, SnsCall) + info(`SNS plugin declared but test declaration didn't match the act. Invalid ${mismatch[0]}\n`) return } diff --git a/tsconfig.json b/tsconfig.json index 55a82b2..172fb14 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,6 @@ "moduleResolution": "node", "target": "ES2022", "module": "ES2022", - "lib": ["ES2022"], "declaration": true, "strict": true, "alwaysStrict": true,