@aws-sdk/lib-sqs 0.0.0-stage → 3.1159.0
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/dist-cjs/index.js +712 -0
- package/dist-es/Message.js +42 -0
- package/dist-es/SQSPoller.js +630 -0
- package/dist-es/errors.js +32 -0
- package/dist-es/index.js +3 -0
- package/dist-es/types.js +1 -0
- package/dist-types/Message.d.ts +52 -0
- package/dist-types/SQSPoller.d.ts +92 -0
- package/dist-types/errors.d.ts +45 -0
- package/dist-types/index.d.ts +28 -0
- package/dist-types/ts3.4/Message.d.ts +29 -0
- package/dist-types/ts3.4/SQSPoller.d.ts +61 -0
- package/dist-types/ts3.4/errors.d.ts +45 -0
- package/dist-types/ts3.4/index.d.ts +11 -0
- package/dist-types/ts3.4/types.d.ts +83 -0
- package/dist-types/types.d.ts +236 -0
- package/package.json +59 -4
- package/README.md +0 -3
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timing options are milliseconds with an `Ms` suffix; the poller converts to
|
|
3
|
+
* seconds when calling SQS.
|
|
4
|
+
*/
|
|
5
|
+
import type { SQSClient, SQSClientConfig, Message as SQSMessage, MessageAttributeValue, MessageSystemAttributeName, BatchResultErrorEntry } from "@aws-sdk/client-sqs";
|
|
6
|
+
export type { SQSClient, SQSClientConfig, SQSMessage, MessageAttributeValue, MessageSystemAttributeName, BatchResultErrorEntry, };
|
|
7
|
+
/**
|
|
8
|
+
* Config options for {@link SQSPoller}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface PollerConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The URL of the SQS queue to poll.
|
|
14
|
+
* @example "https://sqs.us-east-1.amazonaws.com/123456789/my-queue"
|
|
15
|
+
*/
|
|
16
|
+
queueUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Pre-configured SQS client instance.
|
|
19
|
+
* If provided, `clientConfig` is ignored.
|
|
20
|
+
*/
|
|
21
|
+
client?: SQSClient;
|
|
22
|
+
/**
|
|
23
|
+
* Config forwarded to a new `SQSClient` when `client` is not provided.
|
|
24
|
+
* Uses the standard `SQSClientConfig` from `@aws-sdk/client-sqs`.
|
|
25
|
+
*/
|
|
26
|
+
clientConfig?: SQSClientConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Long-poll wait time (0–20_000).
|
|
29
|
+
* Converted to whole seconds for the SQS `ReceiveMessage` API.
|
|
30
|
+
* Use 0 for short polling (not recommended).
|
|
31
|
+
* @defaultValue 20_000
|
|
32
|
+
*/
|
|
33
|
+
receiveWaitTimeMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Messages to request per `ReceiveMessage` call (1–10).
|
|
36
|
+
* @defaultValue 10
|
|
37
|
+
*/
|
|
38
|
+
receiveBatchSize?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Extra delay between polls when the previous poll returned messages.
|
|
41
|
+
* 0 means the next poll starts immediately.
|
|
42
|
+
* @defaultValue 0
|
|
43
|
+
*/
|
|
44
|
+
activePollIntervalMs?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Extra delay between polls when the previous poll returned no messages.
|
|
47
|
+
* @defaultValue 0
|
|
48
|
+
*/
|
|
49
|
+
idlePollIntervalMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Stop polling after this long without receiving a message.
|
|
52
|
+
* `undefined` polls indefinitely.
|
|
53
|
+
* @defaultValue undefined
|
|
54
|
+
*/
|
|
55
|
+
idleTimeoutMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Max messages processed concurrently.
|
|
58
|
+
* The poller pauses `ReceiveMessage` calls when this limit is reached
|
|
59
|
+
* and resumes when in-flight count drops below it.
|
|
60
|
+
* @defaultValue 10
|
|
61
|
+
*/
|
|
62
|
+
maxConcurrency?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Visibility timeout override, rounded up to whole seconds for SQS.
|
|
65
|
+
* When omitted, the queue's default `VisibilityTimeout` applies.
|
|
66
|
+
*/
|
|
67
|
+
visibilityTimeoutMs?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Auto-extend the visibility timeout while a message is being processed.
|
|
70
|
+
* The call is made `extendTimeoutAdvanceMs` before the current timeout expires.
|
|
71
|
+
* @defaultValue false
|
|
72
|
+
*/
|
|
73
|
+
extendTimeout?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* How far ahead of expiry to make the extension call.
|
|
76
|
+
* Only used when `extendTimeout` is `true`.
|
|
77
|
+
* @defaultValue 5_000
|
|
78
|
+
*/
|
|
79
|
+
extendTimeoutAdvanceMs?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Max total time to keep extending the visibility timeout.
|
|
82
|
+
* After this the poller stops extending.
|
|
83
|
+
* Only used when `extendTimeout` is `true`.
|
|
84
|
+
* @defaultValue 43_200_000 (12 hours)
|
|
85
|
+
*/
|
|
86
|
+
maxTimeoutExtensionMs?: number;
|
|
87
|
+
/**
|
|
88
|
+
* When `true` (default), messages are deleted automatically after the
|
|
89
|
+
* `message` handler resolves. Set to `false` for manual deletion via
|
|
90
|
+
* `message.enqueueDelete()`.
|
|
91
|
+
* @defaultValue true
|
|
92
|
+
*/
|
|
93
|
+
deleteMessages?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Batch size for `DeleteMessageBatch` calls (1–10).
|
|
96
|
+
* @defaultValue 10
|
|
97
|
+
*/
|
|
98
|
+
deleteBatchSize?: number;
|
|
99
|
+
/**
|
|
100
|
+
* Max wait for a delete batch to fill before flushing.
|
|
101
|
+
* Lower reduces latency; higher improves batching.
|
|
102
|
+
* @defaultValue 2_000
|
|
103
|
+
*/
|
|
104
|
+
deleteWaitMs?: number;
|
|
105
|
+
/**
|
|
106
|
+
* System attribute names to request with each message.
|
|
107
|
+
* @defaultValue []
|
|
108
|
+
* @example ["All"] or ["ApproximateReceiveCount", "SentTimestamp"]
|
|
109
|
+
*/
|
|
110
|
+
systemAttributeNames?: MessageSystemAttributeName[];
|
|
111
|
+
/**
|
|
112
|
+
* Custom message attribute names to request.
|
|
113
|
+
* @defaultValue []
|
|
114
|
+
* @example ["All"] or ["myAttribute.*"]
|
|
115
|
+
*/
|
|
116
|
+
messageAttributeNames?: string[];
|
|
117
|
+
/**
|
|
118
|
+
* Initial backoff delay after a `ReceiveMessage` error.
|
|
119
|
+
* Doubles on consecutive errors up to `maxBackoffMs`.
|
|
120
|
+
* @defaultValue 1_000
|
|
121
|
+
*/
|
|
122
|
+
backoffMs?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Max backoff ceiling.
|
|
125
|
+
* @defaultValue 30_000
|
|
126
|
+
*/
|
|
127
|
+
maxBackoffMs?: number;
|
|
128
|
+
/**
|
|
129
|
+
* `AbortSignal` for graceful shutdown. When aborted the poller
|
|
130
|
+
* finishes in-flight handlers, flushes pending deletes, then stops.
|
|
131
|
+
*/
|
|
132
|
+
abortSignal?: AbortSignal;
|
|
133
|
+
/**
|
|
134
|
+
* Max wait for in-flight messages to complete during shutdown.
|
|
135
|
+
* @defaultValue 30_000
|
|
136
|
+
*/
|
|
137
|
+
shutdownTimeoutMs?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Callback invoked before each `ReceiveMessage` call. May be async.
|
|
140
|
+
* Throwing (or rejecting) stops the polling loop and emits the error via the
|
|
141
|
+
* `error` event. The poller will not make another request.
|
|
142
|
+
*/
|
|
143
|
+
beforeRequest?: (stats: PollerStats) => void | Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Live stats tracked by the poller.
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export interface PollerStats {
|
|
150
|
+
/** Total `ReceiveMessage` requests sent. */
|
|
151
|
+
requestCount: number;
|
|
152
|
+
/** Total messages received. */
|
|
153
|
+
receivedMessageCount: number;
|
|
154
|
+
/** Total messages successfully deleted. */
|
|
155
|
+
deletedMessageCount: number;
|
|
156
|
+
/** Total errors encountered (receive, delete, extend). */
|
|
157
|
+
errorCount: number;
|
|
158
|
+
/** Timestamp of last received message, or `null`. */
|
|
159
|
+
lastMessageReceivedAt: Date | null;
|
|
160
|
+
/** Timestamp when `start()` was called. */
|
|
161
|
+
pollingStartedAt: Date | null;
|
|
162
|
+
/** Timestamp when the poller stopped, or `null` if still running. */
|
|
163
|
+
pollingStoppedAt: Date | null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* JSON-serializable snapshot of {@link PollerStats}.
|
|
167
|
+
* Dates are converted to ISO-8601 strings.
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
export interface SerializablePollerStats {
|
|
171
|
+
requestCount: number;
|
|
172
|
+
receivedMessageCount: number;
|
|
173
|
+
deletedMessageCount: number;
|
|
174
|
+
errorCount: number;
|
|
175
|
+
lastMessageReceivedAt: string | null;
|
|
176
|
+
pollingStartedAt: string | null;
|
|
177
|
+
pollingStoppedAt: string | null;
|
|
178
|
+
pollingDurationMs: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Events emitted by {@link SQSPoller}.
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
export interface SQSPollerEvents {
|
|
185
|
+
/** A message was received. */
|
|
186
|
+
message: (message: PollerMessage) => void | Promise<void>;
|
|
187
|
+
/** The last `ReceiveMessage` returned no messages. */
|
|
188
|
+
empty: () => void;
|
|
189
|
+
/** The poller stopped due to `idleTimeoutMs` expiring. */
|
|
190
|
+
idle: () => void;
|
|
191
|
+
/** The poller finished shutting down. Fires once per run, however it stopped. */
|
|
192
|
+
stopped: (stats: PollerStats) => void;
|
|
193
|
+
/** A non-fatal error occurred (receive, delete, extend). */
|
|
194
|
+
error: (error: Error) => void;
|
|
195
|
+
/** A message's visibility timeout was extended. */
|
|
196
|
+
timeoutExtended: (message: PollerMessage) => void;
|
|
197
|
+
/** A message's heartbeat expired after `maxTimeoutExtensionMs`. The message may become visible to other consumers. */
|
|
198
|
+
heartbeatExpired: (message: PollerMessage) => void;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Event name literals for {@link SQSPollerEvents}.
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
export type SQSPollerEventName = keyof SQSPollerEvents;
|
|
205
|
+
/**
|
|
206
|
+
* A received SQS message with convenience methods.
|
|
207
|
+
*
|
|
208
|
+
* This interface describes the public surface. The concrete class
|
|
209
|
+
* is in `./Message.ts`.
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
export interface PollerMessage {
|
|
214
|
+
/** Raw SQS `Message` object. */
|
|
215
|
+
readonly raw: SQSMessage;
|
|
216
|
+
/** Message body string. */
|
|
217
|
+
readonly body: string | undefined;
|
|
218
|
+
/** Unique message ID. */
|
|
219
|
+
readonly messageId: string;
|
|
220
|
+
/** Receipt handle for delete / visibility operations. */
|
|
221
|
+
readonly receiptHandle: string;
|
|
222
|
+
/** System attributes (e.g. `ApproximateReceiveCount`). */
|
|
223
|
+
readonly attributes: Partial<Record<MessageSystemAttributeName, string>>;
|
|
224
|
+
/** Custom message attributes. */
|
|
225
|
+
readonly messageAttributes: Record<string, MessageAttributeValue>;
|
|
226
|
+
/** Timestamp when the poller received this message. */
|
|
227
|
+
readonly receivedAt: Date;
|
|
228
|
+
/** Queue this message for batch deletion. */
|
|
229
|
+
enqueueDelete(): void;
|
|
230
|
+
/** Acknowledge the message without deleting it. */
|
|
231
|
+
keep(): void;
|
|
232
|
+
/** Release the message back to the queue immediately (visibility → 0). */
|
|
233
|
+
release(): Promise<void>;
|
|
234
|
+
/** Change the visibility timeout of this message. */
|
|
235
|
+
changeVisibility(timeoutMs: number): Promise<void>;
|
|
236
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/lib-sqs",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.1159.0",
|
|
4
|
+
"description": "SQS message poller with auto-delete, backoff, and graceful shutdown",
|
|
5
|
+
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-sqs",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "AWS SDK for JavaScript Team",
|
|
9
|
+
"url": "https://aws.amazon.com/sdk-for-javascript/"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/aws/aws-sdk-js-v3.git",
|
|
14
|
+
"directory": "lib/lib-sqs"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist-*/**"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist-cjs/index.js",
|
|
20
|
+
"module": "./dist-es/index.js",
|
|
21
|
+
"types": "./dist-types/index.d.ts",
|
|
22
|
+
"typesVersions": {
|
|
23
|
+
"<4.5": {
|
|
24
|
+
"dist-types/*": [
|
|
25
|
+
"dist-types/ts3.4/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
31
|
+
"build:cjs": "node ../../scripts/compilation/inline",
|
|
32
|
+
"build:es": "premove dist-es && tsc -p tsconfig.es.json",
|
|
33
|
+
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
34
|
+
"build:types": "premove dist-types && tsc -p tsconfig.types.json",
|
|
35
|
+
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
36
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
37
|
+
"extract:docs": "api-extractor run --local",
|
|
38
|
+
"test": "yarn g:vitest run",
|
|
39
|
+
"test:watch": "yarn g:vitest watch",
|
|
40
|
+
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts --mode development",
|
|
41
|
+
"test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.mts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"tslib": "^2.6.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@aws-sdk/client-sqs": "3.1159.0",
|
|
48
|
+
"@tsconfig/recommended": "1.0.1",
|
|
49
|
+
"@types/node": "^20.14.8",
|
|
50
|
+
"concurrently": "7.0.0",
|
|
51
|
+
"downlevel-dts": "0.10.1",
|
|
52
|
+
"premove": "4.0.0",
|
|
53
|
+
"typescript": "~7.0.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@aws-sdk/client-sqs": "^3.1159.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=20.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/README.md
DELETED