Skip to content

Commit

Permalink
Add types to SNS plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
abdala committed Nov 18, 2024
1 parent 1bdfc34 commit 559134b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 13 additions & 9 deletions dtc-aws-plugin/src/sns-plugin.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>
messageAttributes?: Record<string, MessageAttributeValue>
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
}

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"moduleResolution": "node",
"target": "ES2022",
"module": "ES2022",
"lib": ["ES2022"],
"declaration": true,
"strict": true,
"alwaysStrict": true,
Expand Down

0 comments on commit 559134b

Please sign in to comment.