-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.ts
60 lines (58 loc) · 2.58 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { merge, cloneDeep, Dictionary } from "lodash";
import {
APIGatewayEvent,
ScheduledEvent,
S3Event,
KinesisStreamEvent,
DynamoDBStreamEvent,
SQSEvent,
SNSEvent,
CloudWatchLogsEvent,
CognitoUserPoolEvent,
} from "aws-lambda";
import {
AlexaSmartHomeEvent,
AlexaSkillEvent,
CloudWatchEvent,
} from "aws-lambda";
import snsTemplate from "./events/aws/sns-template.json";
import sqsTemplate from "./events/aws/sqs-template.json";
import apiGatewayTemplate from "./events/aws/api-gateway-event-template.json";
import scheduledTemplate from "./events/aws/scheduled-template.json";
import s3Template from "./events/aws/s3-template.json";
import kinesisTemplate from "./events/aws/kinesis-template.json";
import dynamoTemplate from "./events/aws/dynamo-stream-event-template.json";
import cloudwatchLogEventTemplate from "./events/aws/cloud-watch-log-event-template.json";
import alexaSmartHomeEventTemplate from "./events/aws/alexa-smart-home-event-template.json";
import alexaSkillEventTemplate from "./events/aws/alexa-skill-event-template.json";
import cloudWatchEventTemplate from "./events/aws/cloud-watch-event-template.json";
import cognitoUserPoolEventTemplate from "./events/aws/cognito-user-pool-event-template.json";
export const dictionary = {
"aws:sns": snsTemplate as SNSEvent,
"aws:sqs": sqsTemplate as SQSEvent,
"aws:apiGateway": apiGatewayTemplate as APIGatewayEvent,
"aws:scheduled": scheduledTemplate as ScheduledEvent,
"aws:s3": s3Template as S3Event,
"aws:kinesis": kinesisTemplate as KinesisStreamEvent,
"aws:dynamo": dynamoTemplate as DynamoDBStreamEvent,
"aws:cloudWatchLog": cloudwatchLogEventTemplate as CloudWatchLogsEvent,
"aws:alexaSmartHome": alexaSmartHomeEventTemplate as AlexaSmartHomeEvent,
"aws:alexaSkill": alexaSkillEventTemplate as AlexaSkillEvent,
"aws:cloudWatch": cloudWatchEventTemplate as CloudWatchEvent,
"aws:iot": {} as any,
"aws:cognitoUserPool": cognitoUserPoolEventTemplate as CognitoUserPoolEvent,
"aws:websocket": apiGatewayTemplate as APIGatewayEvent, // Websockets are included in APIG typedef: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32855/files
};
// https://typeofnan.dev/creating-your-own-deeppartial-type-in-typescript/
type DeepPartial<T> = Partial<{ [P in keyof T]: DeepPartial<T[P]> }>;
export default function createEvent<T extends keyof typeof dictionary, B>(
eventType: T,
body: DeepPartial<typeof dictionary[T]>,
): typeof dictionary[T] {
const event = dictionary[eventType];
let generatedEvent = {};
if (event) {
generatedEvent = merge(cloneDeep(event), body);
}
return generatedEvent;
}