-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic type guard library to validate types in runtime (#26)
* Add generic type guard library to validate types in runtime * Add types to SNS plugin * Temporarily build type-guard first * Bump version * Remove lock from versioning * Use npm i
- Loading branch information
Showing
40 changed files
with
441 additions
and
3,130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist/ | ||
node_modules/ | ||
test-results | ||
test-results | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import {isRecord} from '@cgauge/dtc' | ||
import {EventBridge} from '@aws-sdk/client-eventbridge' | ||
import {info} from '@cgauge/dtc' | ||
import {is, unknown, record, diff} from 'type-assurance' | ||
|
||
type EventBridgeCall = { | ||
eventBus: string | ||
source: string | ||
eventType: string | ||
event: Record<string, unknown> | ||
const EventBridgeAct = { | ||
eventBus: String, | ||
source: String, | ||
eventType: String, | ||
event: record(String, unknown), | ||
} | ||
|
||
const isEventBridgeAct = (v: unknown): v is EventBridgeCall => | ||
isRecord(v) && 'eventBus' in v && 'source' in v && 'eventType' in v && 'event' in v | ||
|
||
const eventBridge = new EventBridge({}) | ||
|
||
export const act = async (args: unknown) => { | ||
if (!isEventBridgeAct(args)) { | ||
return | ||
} | ||
|
||
await eventBridge.putEvents({ | ||
Entries: [ | ||
{ | ||
Time: new Date(), | ||
EventBusName: args.eventBus, | ||
Source: args.source, | ||
DetailType: args.eventType, | ||
Detail: JSON.stringify(args.event), | ||
}, | ||
], | ||
}) | ||
if (!is(args, EventBridgeAct)) { | ||
const mismatch = diff(args, EventBridgeAct) | ||
info(`EventBridge plugin declared but test declaration didn't match the act. Invalid ${mismatch[0]}\n`) | ||
return | ||
} | ||
|
||
await eventBridge.putEvents({ | ||
Entries: [ | ||
{ | ||
Time: new Date(), | ||
EventBusName: args.eventBus, | ||
Source: args.source, | ||
DetailType: args.eventType, | ||
Detail: JSON.stringify(args.event), | ||
}, | ||
], | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.