Skip to content

Commit 87d532c

Browse files
committed
add generic types to dynamodb wrapper, and output correct event type instead of string
1 parent 2a51bc6 commit 87d532c

File tree

7 files changed

+1427
-899
lines changed

7 files changed

+1427
-899
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [3.2.0]  (2020-05-02)
8+
9+
### Changed
10+
11+
- DynamoDB stream wrapper accepts optional type generic for better TypeScript support
12+
- DynamoDB stream wrapper returns string enum for DynamoDB event type instead of 'string'
13+
714
## [3.1.3]  (2020-03-16)
815

916
### Changed
@@ -176,6 +183,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
176183
- Update older libraries
177184
- Now publish from Git tags instead of master pushes
178185

186+
[3.2.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.3...v3.2.0
179187
[3.1.3]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.2...v3.1.3
180188
[3.1.2]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.1...v3.1.2
181189
[3.1.1]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.0...v3.1.1

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,35 +162,41 @@ interface CloudFormationSignature {
162162
```ts
163163
import { dynamodbStream } from '@manwaring/lambda-wrapper';
164164

165-
export const handler = dynamodbStream(async ({ newVersions, success, error }) => {
165+
// By passing in CustomInterface as a generic the async method signature will correctly identify newVersions as an array of CustomInterface, making TypeScript development easier (note that the generic is not required in JavaScript projects)
166+
export const handler = dynamodbStream<CustomInterface>(async ({ newVersions, success, error }) => {
166167
try {
167-
newVersions.forEach(version => console.log(version));
168+
newVersions.forEach((version) => console.log(version));
168169
return success(newVersions);
169170
} catch (err) {
170171
return error(err);
171172
}
172173
});
174+
175+
interface CustomInterface {
176+
id: number;
177+
value: string;
178+
}
173179
```
174180

175181
### Properties and methods available on wrapper signature
176182

177183
```ts
178-
interface DynamoDBStreamSignature {
184+
interface DynamoDBStreamSignature<T> {
179185
event: DynamoDBStreamEvent; // original event
180-
newVersions: any[]; // array of all unmarshalled javascript objects of new images
181-
oldVersions: any[]; // array of all unmarshalled javascript objects of old images
182-
versions: Version[]; // array of full version object (new image, old image, etc - see Version interface)
186+
newVersions: T[]; // array of all unmarshalled javascript objects of new images
187+
oldVersions: T[]; // array of all unmarshalled javascript objects of old images
188+
versions: Version<T>[]; // array of full version object (new image, old image, etc - see Version interface)
183189
success(message?: any): any; // logs and returns the message
184190
error(error?: any): void; // logs the error and throws it
185191
}
186192

187-
interface Version {
188-
newVersion: any; // unmarshalled javascript object of new image (if exists) or null
189-
oldVersion: any; // unmarshalled javascript object of old image (if exists) or null
193+
interface Version<T> {
194+
newVersion: T; // unmarshalled javascript object of new image (if exists) or null
195+
oldVersion: T; // unmarshalled javascript object of old image (if exists) or null
190196
keys: any; // unmarshalled javascript object of keys (includes key values)
191197
tableName: string; // name of the table the object came from
192198
tableArn: string; // arn of the table the object came from
193-
eventName: string; // name of the event (INSERT || MODIFY || REMOVE)
199+
eventName: 'INSERT' | 'MODIFY' | 'REMOVE'; // name of the event (INSERT || MODIFY || REMOVE)
194200
}
195201
```
196202

0 commit comments

Comments
 (0)