Skip to content

Commit baa4966

Browse files
authored
fix: Improve SQSMessageModel types (#1189)
Further work to make `SQSMessageModel` more type-safe. - Properties that have only a getter (no setter) are made readonly - `body` type changed from `string` (incorrect) to `unknown` Jira: [ENG-2733]
1 parent 6a14aca commit baa4966

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/models/SQSMessageModel.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { SQS } from 'aws-sdk';
44
* Message model for SQS.
55
*/
66
export default class Message {
7-
messageId: string;
7+
readonly messageId: string;
88

9-
receiptHandle: string;
9+
readonly receiptHandle: string;
1010

11-
body: string;
11+
readonly body: unknown;
1212

13-
forDeletion = false;
13+
readonly metadata: Record<string, any> = {};
1414

15-
metadata: Record<string, any> = {};
15+
forDeletion = false;
1616

1717
constructor(message: SQS.Message) {
1818
if (!message.MessageId) {
@@ -38,21 +38,21 @@ export default class Message {
3838
/**
3939
* Get message ID.
4040
*/
41-
getMessageId() {
41+
getMessageId(): string {
4242
return this.messageId;
4343
}
4444

4545
/**
4646
* Get message receipt handle.
4747
*/
48-
getReceiptHandle() {
48+
getReceiptHandle(): string {
4949
return this.receiptHandle;
5050
}
5151

5252
/**
5353
* Get message body.
5454
*/
55-
getBody() {
55+
getBody(): unknown {
5656
return this.body;
5757
}
5858

@@ -61,21 +61,21 @@ export default class Message {
6161
*
6262
* @param forDeletion
6363
*/
64-
setForDeletion(forDeletion: boolean) {
64+
setForDeletion(forDeletion: boolean): void {
6565
this.forDeletion = forDeletion;
6666
}
6767

6868
/**
6969
* Whether message is for deletion.
7070
*/
71-
isForDeletion() {
71+
isForDeletion(): boolean {
7272
return this.forDeletion;
7373
}
7474

7575
/**
7676
* Get all of the message metadata.
7777
*/
78-
getMetaData() {
78+
getMetaData(): Record<string, any> {
7979
return this.metadata;
8080
}
8181

@@ -85,7 +85,7 @@ export default class Message {
8585
* @param key
8686
* @param value
8787
*/
88-
setMetaData(key: string, value: any) {
88+
setMetaData(key: string, value: any): this {
8989
this.metadata[key] = value;
9090

9191
return this;

0 commit comments

Comments
 (0)