@fgiova/sqs-consumer 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/cjs/hooks.d.ts +3 -1
- package/dist/cjs/hooks.js +5 -2
- package/dist/cjs/index.d.ts +22 -17
- package/dist/cjs/index.js +9 -2
- package/dist/esm/hooks.d.mts +3 -1
- package/dist/esm/hooks.mjs +5 -2
- package/dist/esm/index.d.mts +22 -17
- package/dist/esm/index.mjs +9 -2
- package/package.json +79 -79
package/README.md
CHANGED
|
@@ -58,12 +58,13 @@ const consumer = new SQSConsumer({
|
|
|
58
58
|
| destroySigner | boolean | false | Whether to destroy the signer when the consumer is destroyed. |
|
|
59
59
|
|
|
60
60
|
### ConsumerOptions
|
|
61
|
-
| Option
|
|
62
|
-
|
|
63
|
-
| visibilityTimeout
|
|
64
|
-
| waitTimeSeconds
|
|
65
|
-
| itemsPerRequest
|
|
66
|
-
| messageAttributeNames
|
|
61
|
+
| Option | Type | Default | Description |
|
|
62
|
+
|-----------------------|----------|---------|------------------------------------------------------------|
|
|
63
|
+
| visibilityTimeout | number | 30 | The visibility timeout for the messages in seconds |
|
|
64
|
+
| waitTimeSeconds | number | 20 | The wait time for the receiveMessage call in seconds |
|
|
65
|
+
| itemsPerRequest | number | 10 | The maximum number of messages to be received at once |
|
|
66
|
+
| messageAttributeNames | string[] | [] | The message attribute names to be included in the response |
|
|
67
|
+
| attributeNames | string[] | [] | The attribute names to be included in the response |
|
|
67
68
|
|
|
68
69
|
### Hooks
|
|
69
70
|
| Option | Type | Description |
|
package/dist/cjs/hooks.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: Function required as generic */
|
|
2
|
+
import type { Message } from "@fgiova/mini-sqs-client";
|
|
1
3
|
import type { Logger } from "./logger";
|
|
2
4
|
export type HookName = "onPoll" | "onMessage" | "onHandlerSuccess" | "onHandlerTimeout" | "onHandlerError" | "onSuccess" | "onError" | "onSQSError";
|
|
3
5
|
export declare class Hooks {
|
|
@@ -6,7 +8,7 @@ export declare class Hooks {
|
|
|
6
8
|
private readonly logger;
|
|
7
9
|
constructor(logger?: Logger);
|
|
8
10
|
addHook(hook: HookName, fn: Function): void;
|
|
9
|
-
runHook(hook: HookName, ...args: any[]): Promise<
|
|
11
|
+
runHook(hook: HookName, ...args: any[]): Promise<boolean | void | Message | Message[]>;
|
|
10
12
|
private runHookWithVoidReturn;
|
|
11
13
|
private runHookWithMessageReturn;
|
|
12
14
|
private runHookWithBooleanReturn;
|
package/dist/cjs/hooks.js
CHANGED
|
@@ -101,7 +101,10 @@ class Hooks {
|
|
|
101
101
|
// biome-ignore lint/suspicious/noExplicitAny: args can be anything
|
|
102
102
|
...args) {
|
|
103
103
|
for (const fn of this.hooks[hookSymbol.S]) {
|
|
104
|
-
|
|
104
|
+
const returnMessage = await fn(message, ...args);
|
|
105
|
+
if (returnMessage) {
|
|
106
|
+
message = returnMessage;
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
109
|
return message;
|
|
107
110
|
}
|
|
@@ -110,7 +113,7 @@ class Hooks {
|
|
|
110
113
|
...args) {
|
|
111
114
|
for (const fn of this.hooks[hookSymbol.S]) {
|
|
112
115
|
const continueLoop = await fn(...args);
|
|
113
|
-
if (
|
|
116
|
+
if (continueLoop === false) {
|
|
114
117
|
return false;
|
|
115
118
|
}
|
|
116
119
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -21,15 +21,19 @@ type ConsumerOptions = {
|
|
|
21
21
|
waitTimeSeconds?: number;
|
|
22
22
|
itemsPerRequest?: number;
|
|
23
23
|
messageAttributeNames?: string[];
|
|
24
|
+
attributeNames?: string[];
|
|
24
25
|
};
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
type hookReturnMessages = Promise<Message[]> | Message[] | Promise<void> | void | undefined;
|
|
27
|
+
type hookReturnMessage = Promise<Message> | Message | Promise<void> | void | undefined;
|
|
28
|
+
type hookReturnBoolean = Promise<boolean> | boolean | Promise<void> | void | undefined;
|
|
29
|
+
export type HooksOptions = {
|
|
30
|
+
onPoll?: (messages: Message[]) => hookReturnMessages;
|
|
31
|
+
onMessage?: (message: Message) => hookReturnMessage;
|
|
32
|
+
onHandlerSuccess?: (message: Message) => hookReturnMessage;
|
|
33
|
+
onHandlerTimeout?: (message: Message) => hookReturnBoolean;
|
|
34
|
+
onHandlerError?: (message: Message, error: Error) => hookReturnBoolean;
|
|
35
|
+
onSuccess?: (message: Message) => hookReturnBoolean;
|
|
36
|
+
onError?: (hook: HookName, message: Message, error: Error) => hookReturnBoolean;
|
|
33
37
|
onSQSError?: (error: Error, message?: Message) => Promise<void>;
|
|
34
38
|
};
|
|
35
39
|
export type SQSConsumerOptions = {
|
|
@@ -63,14 +67,15 @@ export declare class SQSConsumer {
|
|
|
63
67
|
private pollMessages;
|
|
64
68
|
start(): Promise<void>;
|
|
65
69
|
stop(destroy?: boolean): Promise<void>;
|
|
66
|
-
|
|
67
|
-
addHook(hookName: "
|
|
68
|
-
addHook(hookName: "
|
|
69
|
-
addHook(hookName: "
|
|
70
|
-
addHook(hookName: "
|
|
71
|
-
addHook(hookName: "
|
|
72
|
-
addHook(hookName: "
|
|
73
|
-
addHook(hookName: "
|
|
74
|
-
addHook(hookName:
|
|
70
|
+
get isRunning(): boolean;
|
|
71
|
+
addHook(hookName: "onPoll", value: (messages: Message[]) => Promise<Message[]>): this;
|
|
72
|
+
addHook(hookName: "onMessage", value: (message: Message) => Promise<Message>): this;
|
|
73
|
+
addHook(hookName: "onHandlerSuccess", value: (message: Message) => Promise<Message>): this;
|
|
74
|
+
addHook(hookName: "onHandlerTimeout", value: (message: Message) => Promise<boolean>): this;
|
|
75
|
+
addHook(hookName: "onHandlerError", value: (message: Message, error: Error) => Promise<boolean>): this;
|
|
76
|
+
addHook(hookName: "onSuccess", value: (message: Message) => Promise<boolean>): this;
|
|
77
|
+
addHook(hookName: "onError", value: (hook: HookName, message: Message, error: Error) => Promise<boolean>): this;
|
|
78
|
+
addHook(hookName: "onSQSError", value: (error: Error, message?: Message) => Promise<void>): this;
|
|
79
|
+
addHook(hookName: HookName, value: Function): this;
|
|
75
80
|
}
|
|
76
81
|
export {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -41,6 +41,7 @@ class SQSConsumer {
|
|
|
41
41
|
waitTimeSeconds: options.consumerOptions?.waitTimeSeconds ?? 20,
|
|
42
42
|
itemsPerRequest: options.consumerOptions?.itemsPerRequest ?? 10,
|
|
43
43
|
messageAttributeNames: options.consumerOptions?.messageAttributeNames ?? [],
|
|
44
|
+
attributeNames: options.consumerOptions?.attributeNames ?? [],
|
|
44
45
|
};
|
|
45
46
|
this.sqsClient =
|
|
46
47
|
options.clientOptions?.sqsClient ??
|
|
@@ -92,7 +93,7 @@ class SQSConsumer {
|
|
|
92
93
|
else {
|
|
93
94
|
handlerResult = await handler(message);
|
|
94
95
|
}
|
|
95
|
-
await
|
|
96
|
+
await this.hooks.runHook("onHandlerSuccess", message);
|
|
96
97
|
return handlerResult;
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
@@ -151,6 +152,7 @@ class SQSConsumer {
|
|
|
151
152
|
MaxNumberOfMessages: this.consumerOptions.itemsPerRequest,
|
|
152
153
|
VisibilityTimeout: visibilityTimeout,
|
|
153
154
|
MessageAttributeNames: this.consumerOptions.messageAttributeNames,
|
|
155
|
+
AttributeNames: this.consumerOptions.attributeNames,
|
|
154
156
|
});
|
|
155
157
|
/* c8 ignore next 1 */
|
|
156
158
|
const messages = messagesResult.Messages ?? [];
|
|
@@ -213,8 +215,13 @@ class SQSConsumer {
|
|
|
213
215
|
this.destroyed = true;
|
|
214
216
|
}
|
|
215
217
|
}
|
|
218
|
+
/* c8 ignore next 3 */
|
|
219
|
+
get isRunning() {
|
|
220
|
+
return this.running;
|
|
221
|
+
}
|
|
216
222
|
addHook(hookName, value) {
|
|
217
|
-
|
|
223
|
+
this.hooks.addHook(hookName, value);
|
|
224
|
+
return this;
|
|
218
225
|
}
|
|
219
226
|
}
|
|
220
227
|
exports.SQSConsumer = SQSConsumer;
|
package/dist/esm/hooks.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: Function required as generic */
|
|
2
|
+
import type { Message } from "@fgiova/mini-sqs-client";
|
|
1
3
|
import type { Logger } from "./logger.mjs";
|
|
2
4
|
export type HookName = "onPoll" | "onMessage" | "onHandlerSuccess" | "onHandlerTimeout" | "onHandlerError" | "onSuccess" | "onError" | "onSQSError";
|
|
3
5
|
export declare class Hooks {
|
|
@@ -6,7 +8,7 @@ export declare class Hooks {
|
|
|
6
8
|
private readonly logger;
|
|
7
9
|
constructor(logger?: Logger);
|
|
8
10
|
addHook(hook: HookName, fn: Function): void;
|
|
9
|
-
runHook(hook: HookName, ...args: any[]): Promise<
|
|
11
|
+
runHook(hook: HookName, ...args: any[]): Promise<boolean | void | Message | Message[]>;
|
|
10
12
|
private runHookWithVoidReturn;
|
|
11
13
|
private runHookWithMessageReturn;
|
|
12
14
|
private runHookWithBooleanReturn;
|
package/dist/esm/hooks.mjs
CHANGED
|
@@ -98,7 +98,10 @@ export class Hooks {
|
|
|
98
98
|
// biome-ignore lint/suspicious/noExplicitAny: args can be anything
|
|
99
99
|
...args) {
|
|
100
100
|
for (const fn of this.hooks[hookSymbol.S]) {
|
|
101
|
-
|
|
101
|
+
const returnMessage = await fn(message, ...args);
|
|
102
|
+
if (returnMessage) {
|
|
103
|
+
message = returnMessage;
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
106
|
return message;
|
|
104
107
|
}
|
|
@@ -107,7 +110,7 @@ export class Hooks {
|
|
|
107
110
|
...args) {
|
|
108
111
|
for (const fn of this.hooks[hookSymbol.S]) {
|
|
109
112
|
const continueLoop = await fn(...args);
|
|
110
|
-
if (
|
|
113
|
+
if (continueLoop === false) {
|
|
111
114
|
return false;
|
|
112
115
|
}
|
|
113
116
|
}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -21,15 +21,19 @@ type ConsumerOptions = {
|
|
|
21
21
|
waitTimeSeconds?: number;
|
|
22
22
|
itemsPerRequest?: number;
|
|
23
23
|
messageAttributeNames?: string[];
|
|
24
|
+
attributeNames?: string[];
|
|
24
25
|
};
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
type hookReturnMessages = Promise<Message[]> | Message[] | Promise<void> | void | undefined;
|
|
27
|
+
type hookReturnMessage = Promise<Message> | Message | Promise<void> | void | undefined;
|
|
28
|
+
type hookReturnBoolean = Promise<boolean> | boolean | Promise<void> | void | undefined;
|
|
29
|
+
export type HooksOptions = {
|
|
30
|
+
onPoll?: (messages: Message[]) => hookReturnMessages;
|
|
31
|
+
onMessage?: (message: Message) => hookReturnMessage;
|
|
32
|
+
onHandlerSuccess?: (message: Message) => hookReturnMessage;
|
|
33
|
+
onHandlerTimeout?: (message: Message) => hookReturnBoolean;
|
|
34
|
+
onHandlerError?: (message: Message, error: Error) => hookReturnBoolean;
|
|
35
|
+
onSuccess?: (message: Message) => hookReturnBoolean;
|
|
36
|
+
onError?: (hook: HookName, message: Message, error: Error) => hookReturnBoolean;
|
|
33
37
|
onSQSError?: (error: Error, message?: Message) => Promise<void>;
|
|
34
38
|
};
|
|
35
39
|
export type SQSConsumerOptions = {
|
|
@@ -63,14 +67,15 @@ export declare class SQSConsumer {
|
|
|
63
67
|
private pollMessages;
|
|
64
68
|
start(): Promise<void>;
|
|
65
69
|
stop(destroy?: boolean): Promise<void>;
|
|
66
|
-
|
|
67
|
-
addHook(hookName: "
|
|
68
|
-
addHook(hookName: "
|
|
69
|
-
addHook(hookName: "
|
|
70
|
-
addHook(hookName: "
|
|
71
|
-
addHook(hookName: "
|
|
72
|
-
addHook(hookName: "
|
|
73
|
-
addHook(hookName: "
|
|
74
|
-
addHook(hookName:
|
|
70
|
+
get isRunning(): boolean;
|
|
71
|
+
addHook(hookName: "onPoll", value: (messages: Message[]) => Promise<Message[]>): this;
|
|
72
|
+
addHook(hookName: "onMessage", value: (message: Message) => Promise<Message>): this;
|
|
73
|
+
addHook(hookName: "onHandlerSuccess", value: (message: Message) => Promise<Message>): this;
|
|
74
|
+
addHook(hookName: "onHandlerTimeout", value: (message: Message) => Promise<boolean>): this;
|
|
75
|
+
addHook(hookName: "onHandlerError", value: (message: Message, error: Error) => Promise<boolean>): this;
|
|
76
|
+
addHook(hookName: "onSuccess", value: (message: Message) => Promise<boolean>): this;
|
|
77
|
+
addHook(hookName: "onError", value: (hook: HookName, message: Message, error: Error) => Promise<boolean>): this;
|
|
78
|
+
addHook(hookName: "onSQSError", value: (error: Error, message?: Message) => Promise<void>): this;
|
|
79
|
+
addHook(hookName: HookName, value: Function): this;
|
|
75
80
|
}
|
|
76
81
|
export {};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -35,6 +35,7 @@ export class SQSConsumer {
|
|
|
35
35
|
waitTimeSeconds: options.consumerOptions?.waitTimeSeconds ?? 20,
|
|
36
36
|
itemsPerRequest: options.consumerOptions?.itemsPerRequest ?? 10,
|
|
37
37
|
messageAttributeNames: options.consumerOptions?.messageAttributeNames ?? [],
|
|
38
|
+
attributeNames: options.consumerOptions?.attributeNames ?? [],
|
|
38
39
|
};
|
|
39
40
|
this.sqsClient =
|
|
40
41
|
options.clientOptions?.sqsClient ??
|
|
@@ -86,7 +87,7 @@ export class SQSConsumer {
|
|
|
86
87
|
else {
|
|
87
88
|
handlerResult = await handler(message);
|
|
88
89
|
}
|
|
89
|
-
await
|
|
90
|
+
await this.hooks.runHook("onHandlerSuccess", message);
|
|
90
91
|
return handlerResult;
|
|
91
92
|
}
|
|
92
93
|
catch (error) {
|
|
@@ -145,6 +146,7 @@ export class SQSConsumer {
|
|
|
145
146
|
MaxNumberOfMessages: this.consumerOptions.itemsPerRequest,
|
|
146
147
|
VisibilityTimeout: visibilityTimeout,
|
|
147
148
|
MessageAttributeNames: this.consumerOptions.messageAttributeNames,
|
|
149
|
+
AttributeNames: this.consumerOptions.attributeNames,
|
|
148
150
|
});
|
|
149
151
|
/* c8 ignore next 1 */
|
|
150
152
|
const messages = messagesResult.Messages ?? [];
|
|
@@ -207,7 +209,12 @@ export class SQSConsumer {
|
|
|
207
209
|
this.destroyed = true;
|
|
208
210
|
}
|
|
209
211
|
}
|
|
212
|
+
/* c8 ignore next 3 */
|
|
213
|
+
get isRunning() {
|
|
214
|
+
return this.running;
|
|
215
|
+
}
|
|
210
216
|
addHook(hookName, value) {
|
|
211
|
-
|
|
217
|
+
this.hooks.addHook(hookName, value);
|
|
218
|
+
return this;
|
|
212
219
|
}
|
|
213
220
|
}
|
package/package.json
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
2
|
+
"name": "@fgiova/sqs-consumer",
|
|
3
|
+
"version": "2.1.2",
|
|
4
|
+
"main": "./dist/cjs/index.js",
|
|
5
|
+
"types": "./dist/cjs/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": {
|
|
9
|
+
"types": "./dist/esm/index.d.mts",
|
|
10
|
+
"default": "./dist/esm/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/cjs/index.d.ts",
|
|
14
|
+
"default": "./dist/cjs/index.js"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"preBuild": "npm run clean",
|
|
24
|
+
"build": "esmBuilder",
|
|
25
|
+
"lint": "biome ci ./src ./test",
|
|
26
|
+
"fix": "biome check --write ./src ./test",
|
|
27
|
+
"test": "tap",
|
|
28
|
+
"test:debug": "tap --only --timeout=0",
|
|
29
|
+
"test:coverage": "tap --coverage-report=lcovonly --coverage-report=text",
|
|
30
|
+
"test:local": "TEST_LOCAL=true tap"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/fgiova/sqs-consumer.git"
|
|
35
|
+
},
|
|
36
|
+
"author": "Francesco Giovannini <fgiova@fgiova.com>",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"aws",
|
|
40
|
+
"sqs",
|
|
41
|
+
"sqs-consumer"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20.0.0"
|
|
48
|
+
},
|
|
49
|
+
"tap": {
|
|
50
|
+
"show-full-coverage": true,
|
|
51
|
+
"before": "./test/scripts/executors/before.js",
|
|
52
|
+
"after": "./test/scripts/executors/teardown.js",
|
|
53
|
+
"exclude": [
|
|
54
|
+
"test/helpers/**/*",
|
|
55
|
+
"test/scripts/**/*"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@fgiova/mini-sqs-client": "^3.2.1",
|
|
60
|
+
"@watchable/unpromise": "^1.0.2",
|
|
61
|
+
"p-map": "^7.0.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@fgiova/aws-signature": "^3.1.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@aws-sdk/client-sqs": "^3.758.0",
|
|
68
|
+
"@biomejs/biome": "2.2.2",
|
|
69
|
+
"@fgiova/cjs-esm-ts-builder": "^1.2.0",
|
|
70
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
71
|
+
"@semantic-release/git": "^10.0.1",
|
|
72
|
+
"@tsconfig/node20": "^20.1.4",
|
|
73
|
+
"@types/node": "^20.17.23",
|
|
74
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
75
|
+
"semantic-release": "^24.2.3",
|
|
76
|
+
"tap": "^21.1.0",
|
|
77
|
+
"testcontainers": "^11.5.1",
|
|
78
|
+
"ts-node": "^10.9.2",
|
|
79
|
+
"typescript": "^5.8.2"
|
|
80
|
+
}
|
|
81
81
|
}
|