Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
marciocadev committed Apr 6, 2024
1 parent ccad721 commit 3e0e736
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 153 deletions.
2 changes: 1 addition & 1 deletion dynamodb/dynamodb.extern.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default interface extern {
createClient: (options: ClientConfig) => Promise<Client$Inflight>,
createDocumentClient: (options?: (CreateDocumentClientOptions) | undefined) => Promise<DocumentClient$Inflight>,
getPort: () => Promise<number>,
processRecordsAsync: (endpoint: string, tableName: string, handler: (arg0: StreamRecord) => Promise<void>, options?: (StreamConsumerOptions) | undefined) => Promise<void>,
processRecordsAsync: (endpoint: string, tableName: string, handler: (arg0: StreamRecord) => Promise<void>, eventName: string, options?: (StreamConsumerOptions) | undefined) => Promise<void>,
unmarshall: (item: Readonly<any>, options?: (Readonly<any>) | undefined) => Promise<Readonly<any>>,
}
export interface Credentials {
Expand Down
36 changes: 19 additions & 17 deletions dynamodb/dynamodb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ const processStreamRecords = async (client, StreamArn, handler, eventType, optio
});

for (const record of recordsData.Records) {
try {
await handler({
eventId: record.eventID,
eventName: record.eventName,
dynamodb: {
ApproximateCreationDateTime:
record.dynamodb.ApproximateCreationDateTime,
Keys: record.dynamodb.Keys,
NewImage: record.dynamodb.NewImage,
OldImage: record.dynamodb.OldImage,
SequenceNumber: record.dynamodb.SequenceNumber,
SizeBytes: record.dynamodb.SizeBytes,
StreamViewType: record.dynamodb.StreamViewType,
},
});
} catch (error) {
console.error("Error processing stream record:", error, record);
if (!event || record.eventName == event) {
try {
await handler({
eventId: record.eventID,
eventName: record.eventName,
dynamodb: {
ApproximateCreationDateTime:
record.dynamodb.ApproximateCreationDateTime,
Keys: record.dynamodb.Keys,
NewImage: record.dynamodb.NewImage,
OldImage: record.dynamodb.OldImage,
SequenceNumber: record.dynamodb.SequenceNumber,
SizeBytes: record.dynamodb.SizeBytes,
StreamViewType: record.dynamodb.StreamViewType,
},
});
} catch (error) {
console.error("Error processing stream record:", error, record);
}
}
}

Expand Down
Loading

0 comments on commit 3e0e736

Please sign in to comment.