From 40c8eeeb857d4cc54e4e21f4e3d7ff9bf1da1cf0 Mon Sep 17 00:00:00 2001 From: "Kylo@Cove" Date: Tue, 31 Dec 2019 09:48:35 -0700 Subject: [PATCH 1/2] Added Partial to the creatEvent the body args type --- lib/index.ts | 2 +- package-lock.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index c1b4b45..f9dbf63 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -48,7 +48,7 @@ export const dictionary = { export default function createEvent( eventType: T, - body: typeof dictionary[T], + body: Partial, ): typeof dictionary[T] { const event = dictionary[eventType]; let generatedEvent = {}; diff --git a/package-lock.json b/package-lock.json index eaa1441..9acf112 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@serverless/event-mocks", - "version": "0.0.1", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { From 5f0dd17a13fd13ebafc887aac2c3c95b9d1b1b38 Mon Sep 17 00:00:00 2001 From: Kylo Jorgensen Date: Wed, 17 May 2023 12:04:17 -0600 Subject: [PATCH 2/2] DeepPartial --- lib/index.ts | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index f9dbf63..1ffec5d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -29,26 +29,35 @@ import alexaSkillEventTemplate from "./events/aws/alexa-skill-event-template.jso import cloudWatchEventTemplate from "./events/aws/cloud-watch-event-template.json"; import cognitoUserPoolEventTemplate from "./events/aws/cognito-user-pool-event-template.json"; +type DeepPartial = T extends object + ? { + [P in keyof T]?: DeepPartial; + } + : T; + 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:sns": snsTemplate as DeepPartial, + "aws:sqs": sqsTemplate as DeepPartial, + "aws:apiGateway": apiGatewayTemplate as DeepPartial, + "aws:scheduled": scheduledTemplate as DeepPartial, + "aws:s3": s3Template as DeepPartial, + "aws:kinesis": kinesisTemplate as DeepPartial, + "aws:dynamo": dynamoTemplate as DeepPartial, + "aws:cloudWatchLog": + cloudwatchLogEventTemplate as DeepPartial, + "aws:alexaSmartHome": + alexaSmartHomeEventTemplate as DeepPartial, + "aws:alexaSkill": alexaSkillEventTemplate as DeepPartial, + "aws:cloudWatch": cloudWatchEventTemplate as DeepPartial, "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 + "aws:cognitoUserPool": + cognitoUserPoolEventTemplate as DeepPartial, + "aws:websocket": apiGatewayTemplate as DeepPartial, // Websockets are included in APIG typedef: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32855/files }; export default function createEvent( eventType: T, - body: Partial, + body: typeof dictionary[T] ): typeof dictionary[T] { const event = dictionary[eventType]; let generatedEvent = {};