@vercel/queue 0.0.0-alpha.29 → 0.0.0-alpha.30
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 +67 -1
- package/dist/index.d.mts +3 -255
- package/dist/index.d.ts +3 -255
- package/dist/pages.d.mts +47 -0
- package/dist/pages.d.ts +47 -0
- package/dist/pages.js +1250 -0
- package/dist/pages.js.map +1 -0
- package/dist/pages.mjs +1223 -0
- package/dist/pages.mjs.map +1 -0
- package/dist/types-JvOenjfT.d.mts +256 -0
- package/dist/types-JvOenjfT.d.ts +256 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -134,6 +134,8 @@ Messages are consumed using API routes that Vercel automatically triggers when m
|
|
|
134
134
|
|
|
135
135
|
#### 1. Create API Routes
|
|
136
136
|
|
|
137
|
+
##### App Router (Recommended)
|
|
138
|
+
|
|
137
139
|
The recommended approach is to handle multiple topics and consumers in a single API route to keep your `vercel.json` configuration simple:
|
|
138
140
|
|
|
139
141
|
```typescript
|
|
@@ -179,9 +181,42 @@ export const POST = handleCallback({
|
|
|
179
181
|
|
|
180
182
|
While you can split handlers into separate routes if needed (e.g., for code organization or deployment flexibility), consolidating them in one route is recommended for simpler configuration.
|
|
181
183
|
|
|
184
|
+
##### Pages Router
|
|
185
|
+
|
|
186
|
+
For Next.js Pages Router, import from `@vercel/queue/pages` to get a handler compatible with the Pages Router API (`NextApiRequest`/`NextApiResponse`):
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
// pages/api/queue.ts
|
|
190
|
+
import { handleCallback } from "@vercel/queue/pages";
|
|
191
|
+
|
|
192
|
+
export default handleCallback({
|
|
193
|
+
"my-topic": {
|
|
194
|
+
"my-consumer": async (message, metadata) => {
|
|
195
|
+
console.log("Processing message:", message);
|
|
196
|
+
await processMessage(message);
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
"order-events": {
|
|
200
|
+
fulfillment: async (order, metadata) => {
|
|
201
|
+
if (!isSystemReady()) {
|
|
202
|
+
return { timeoutSeconds: 300 };
|
|
203
|
+
}
|
|
204
|
+
await processOrder(order);
|
|
205
|
+
},
|
|
206
|
+
analytics: async (order, metadata) => {
|
|
207
|
+
await trackOrder(order);
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The `/pages` subpath export automatically adapts the handler to work with the Pages Router API.
|
|
214
|
+
|
|
182
215
|
#### 2. Configure vercel.json
|
|
183
216
|
|
|
184
|
-
Configure which topics and consumers your API route handles
|
|
217
|
+
Configure which topics and consumers your API route handles.
|
|
218
|
+
|
|
219
|
+
**For App Router:**
|
|
185
220
|
|
|
186
221
|
```json
|
|
187
222
|
{
|
|
@@ -212,6 +247,37 @@ Configure which topics and consumers your API route handles:
|
|
|
212
247
|
}
|
|
213
248
|
```
|
|
214
249
|
|
|
250
|
+
**For Pages Router:**
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"functions": {
|
|
255
|
+
"pages/api/queue.ts": {
|
|
256
|
+
"experimentalTriggers": [
|
|
257
|
+
{
|
|
258
|
+
"type": "queue/v1beta",
|
|
259
|
+
"topic": "my-topic",
|
|
260
|
+
"consumer": "my-consumer",
|
|
261
|
+
"retryAfterSeconds": 60,
|
|
262
|
+
"initialDelaySeconds": 0
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"type": "queue/v1beta",
|
|
266
|
+
"topic": "order-events",
|
|
267
|
+
"consumer": "fulfillment"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"type": "queue/v1beta",
|
|
271
|
+
"topic": "order-events",
|
|
272
|
+
"consumer": "analytics",
|
|
273
|
+
"retryAfterSeconds": 300
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
215
281
|
### Key Concepts
|
|
216
282
|
|
|
217
283
|
- **Topics**: Named message channels that can have multiple consumer groups
|
package/dist/index.d.mts
CHANGED
|
@@ -1,257 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
interface Transport<T = unknown> {
|
|
5
|
-
/**
|
|
6
|
-
* Serialize a value to a buffer or stream for transmission
|
|
7
|
-
*/
|
|
8
|
-
serialize(value: T): Buffer | ReadableStream<Uint8Array>;
|
|
9
|
-
/**
|
|
10
|
-
* Deserialize a readable stream back to the original value
|
|
11
|
-
*/
|
|
12
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Optional cleanup method for deserialized payloads that may contain resources
|
|
15
|
-
* Should be called when the payload is no longer needed, especially in error cases
|
|
16
|
-
* @param payload The deserialized payload to clean up
|
|
17
|
-
*/
|
|
18
|
-
finalize?(payload: T): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* MIME type for this serialization format
|
|
21
|
-
*/
|
|
22
|
-
contentType: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Built-in JSON serializer/deserializer
|
|
26
|
-
* This implementation reads the entire stream into memory for JSON parsing
|
|
27
|
-
*/
|
|
28
|
-
declare class JsonTransport<T = unknown> implements Transport<T> {
|
|
29
|
-
readonly contentType = "application/json";
|
|
30
|
-
readonly replacer?: Parameters<typeof JSON.parse>[1];
|
|
31
|
-
readonly reviver?: Parameters<typeof JSON.parse>[1];
|
|
32
|
-
constructor(options?: {
|
|
33
|
-
replacer?: Parameters<typeof JSON.parse>[1];
|
|
34
|
-
reviver?: Parameters<typeof JSON.parse>[1];
|
|
35
|
-
});
|
|
36
|
-
serialize(value: T): Buffer;
|
|
37
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Built-in Buffer serializer/deserializer (reads entire stream into a Buffer)
|
|
41
|
-
*/
|
|
42
|
-
declare class BufferTransport implements Transport<Buffer> {
|
|
43
|
-
readonly contentType = "application/octet-stream";
|
|
44
|
-
serialize(value: Buffer): Buffer;
|
|
45
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<Buffer>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Stream serializer/deserializer (pass-through for streaming binary data)
|
|
49
|
-
* This is ideal for large payloads that don't need to be buffered in memory
|
|
50
|
-
*
|
|
51
|
-
* IMPORTANT: When using StreamTransport, you must call finalize(payload) when done
|
|
52
|
-
* processing the message to prevent resource leaks, especially in error cases.
|
|
53
|
-
* ConsumerGroup handles this automatically, but direct QueueClient usage requires manual cleanup.
|
|
54
|
-
*
|
|
55
|
-
* Example usage:
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const transport = new StreamTransport();
|
|
58
|
-
* try {
|
|
59
|
-
* for await (const message of client.receiveMessages(options, transport)) {
|
|
60
|
-
* // Process the stream...
|
|
61
|
-
* const reader = message.payload.getReader();
|
|
62
|
-
* // ... handle stream data
|
|
63
|
-
* }
|
|
64
|
-
* } catch (error) {
|
|
65
|
-
* // Cleanup is handled automatically by ConsumerGroup
|
|
66
|
-
* // or manually: await transport.finalize(message.payload);
|
|
67
|
-
* }
|
|
68
|
-
*/
|
|
69
|
-
declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
|
|
70
|
-
readonly contentType = "application/octet-stream";
|
|
71
|
-
serialize(value: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
|
|
72
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>>;
|
|
73
|
-
finalize(payload: ReadableStream<Uint8Array>): Promise<void>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Vercel Queue Service client types
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Shared options for publishing messages
|
|
82
|
-
*/
|
|
83
|
-
interface PublishOptions {
|
|
84
|
-
/**
|
|
85
|
-
* Unique key to prevent duplicate message submissions
|
|
86
|
-
* @default random UUID
|
|
87
|
-
*/
|
|
88
|
-
idempotencyKey?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Message retention time in seconds
|
|
91
|
-
* @default 86400 (24 hours)
|
|
92
|
-
* @min 60
|
|
93
|
-
* @max 86400
|
|
94
|
-
*/
|
|
95
|
-
retentionSeconds?: number;
|
|
96
|
-
/**
|
|
97
|
-
* Explicit deployment identifier to include in the `Vqs-Deployment-Id` header
|
|
98
|
-
* If provided, this takes precedence over any value from the environment
|
|
99
|
-
*/
|
|
100
|
-
deploymentId?: string;
|
|
101
|
-
}
|
|
102
|
-
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
103
|
-
/**
|
|
104
|
-
* The queue name to send the message to
|
|
105
|
-
*/
|
|
106
|
-
queueName: string;
|
|
107
|
-
/**
|
|
108
|
-
* The message payload
|
|
109
|
-
*/
|
|
110
|
-
payload: T;
|
|
111
|
-
}
|
|
112
|
-
interface SendMessageResponse {
|
|
113
|
-
/**
|
|
114
|
-
* The generated message ID
|
|
115
|
-
*/
|
|
116
|
-
messageId: string;
|
|
117
|
-
}
|
|
118
|
-
interface Message<T = unknown> {
|
|
119
|
-
/**
|
|
120
|
-
* The message ID
|
|
121
|
-
*/
|
|
122
|
-
messageId: string;
|
|
123
|
-
/**
|
|
124
|
-
* The deserialized message payload
|
|
125
|
-
* Note: If using streaming transports, ensure proper cleanup by calling transport.finalize(payload)
|
|
126
|
-
* when done processing, especially in error cases
|
|
127
|
-
*/
|
|
128
|
-
payload: T;
|
|
129
|
-
/**
|
|
130
|
-
* Number of times this message has been delivered
|
|
131
|
-
*/
|
|
132
|
-
deliveryCount: number;
|
|
133
|
-
/**
|
|
134
|
-
* When the message was created
|
|
135
|
-
*/
|
|
136
|
-
createdAt: Date;
|
|
137
|
-
/**
|
|
138
|
-
* MIME type of the message content
|
|
139
|
-
*/
|
|
140
|
-
contentType: string;
|
|
141
|
-
/**
|
|
142
|
-
* Unique ticket for this message delivery (required for delete/patch operations)
|
|
143
|
-
*/
|
|
144
|
-
ticket: string;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Result indicating the message should be timed out for retry later
|
|
148
|
-
*/
|
|
149
|
-
interface MessageTimeoutResult {
|
|
150
|
-
/**
|
|
151
|
-
* Time in seconds before the message becomes visible again
|
|
152
|
-
*/
|
|
153
|
-
timeoutSeconds: number;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Result returned by message handlers
|
|
157
|
-
*/
|
|
158
|
-
type MessageHandlerResult = void | MessageTimeoutResult;
|
|
159
|
-
/**
|
|
160
|
-
* Message metadata provided to handlers
|
|
161
|
-
*/
|
|
162
|
-
interface MessageMetadata {
|
|
163
|
-
messageId: string;
|
|
164
|
-
deliveryCount: number;
|
|
165
|
-
createdAt: Date;
|
|
166
|
-
topicName: string;
|
|
167
|
-
consumerGroup: string;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Message handler function type
|
|
171
|
-
*/
|
|
172
|
-
type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
|
|
173
|
-
/**
|
|
174
|
-
* Options for creating a ConsumerGroup instance
|
|
175
|
-
*/
|
|
176
|
-
interface ConsumerGroupOptions<T = unknown> {
|
|
177
|
-
/**
|
|
178
|
-
* Serializer/deserializer for the payload
|
|
179
|
-
* @default JsonTransport instance
|
|
180
|
-
*/
|
|
181
|
-
transport?: Transport<T>;
|
|
182
|
-
/**
|
|
183
|
-
* Time in seconds that messages will be invisible to other consumers
|
|
184
|
-
* @default 30
|
|
185
|
-
*/
|
|
186
|
-
visibilityTimeoutSeconds?: number;
|
|
187
|
-
/**
|
|
188
|
-
* How often to refresh the visibility timeout during processing (in seconds)
|
|
189
|
-
* @default 10
|
|
190
|
-
*/
|
|
191
|
-
refreshInterval?: number;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Error thrown when a message is not found (404)
|
|
195
|
-
*/
|
|
196
|
-
declare class MessageNotFoundError extends Error {
|
|
197
|
-
constructor(messageId: string);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Error thrown when a message is not available for processing (409)
|
|
201
|
-
* This can happen when the message is in the wrong state, already claimed, etc.
|
|
202
|
-
*/
|
|
203
|
-
declare class MessageNotAvailableError extends Error {
|
|
204
|
-
constructor(messageId: string, reason?: string);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Error thrown when message data is corrupted or can't be parsed
|
|
208
|
-
*/
|
|
209
|
-
declare class MessageCorruptedError extends Error {
|
|
210
|
-
constructor(messageId: string, reason: string);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Error thrown when there are no messages available in the queue (204)
|
|
214
|
-
*/
|
|
215
|
-
declare class QueueEmptyError extends Error {
|
|
216
|
-
constructor(queueName: string, consumerGroup: string);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Error thrown when a message is temporarily locked (423)
|
|
220
|
-
*/
|
|
221
|
-
declare class MessageLockedError extends Error {
|
|
222
|
-
readonly retryAfter?: number;
|
|
223
|
-
constructor(messageId: string, retryAfter?: number);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Error thrown when authentication fails (401)
|
|
227
|
-
*/
|
|
228
|
-
declare class UnauthorizedError extends Error {
|
|
229
|
-
constructor(message?: string);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Error thrown when access is forbidden (403)
|
|
233
|
-
*/
|
|
234
|
-
declare class ForbiddenError extends Error {
|
|
235
|
-
constructor(message?: string);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Error thrown for bad requests (400)
|
|
239
|
-
*/
|
|
240
|
-
declare class BadRequestError extends Error {
|
|
241
|
-
constructor(message: string);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Error thrown for internal server errors (500)
|
|
245
|
-
*/
|
|
246
|
-
declare class InternalServerError extends Error {
|
|
247
|
-
constructor(message?: string);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Error thrown when batch limit parameter is invalid
|
|
251
|
-
*/
|
|
252
|
-
declare class InvalidLimitError extends Error {
|
|
253
|
-
constructor(limit: number, min?: number, max?: number);
|
|
254
|
-
}
|
|
1
|
+
import { M as MessageHandler, C as ConsumerGroupOptions, P as PublishOptions, T as Transport } from './types-JvOenjfT.mjs';
|
|
2
|
+
export { a as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, b as InvalidLimitError, J as JsonTransport, g as Message, c as MessageCorruptedError, h as MessageHandlerResult, d as MessageLockedError, i as MessageMetadata, e as MessageNotAvailableError, f as MessageNotFoundError, j as MessageTimeoutResult, Q as QueueEmptyError, k as SendMessageOptions, l as SendMessageResponse, S as StreamTransport, U as UnauthorizedError } from './types-JvOenjfT.mjs';
|
|
255
3
|
|
|
256
4
|
/**
|
|
257
5
|
* Options for the consume method
|
|
@@ -408,4 +156,4 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
|
|
|
408
156
|
*/
|
|
409
157
|
declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
|
|
410
158
|
|
|
411
|
-
export {
|
|
159
|
+
export { MessageHandler, type ParsedCallbackRequest, PublishOptions, type ReceiveOptions, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,257 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
interface Transport<T = unknown> {
|
|
5
|
-
/**
|
|
6
|
-
* Serialize a value to a buffer or stream for transmission
|
|
7
|
-
*/
|
|
8
|
-
serialize(value: T): Buffer | ReadableStream<Uint8Array>;
|
|
9
|
-
/**
|
|
10
|
-
* Deserialize a readable stream back to the original value
|
|
11
|
-
*/
|
|
12
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Optional cleanup method for deserialized payloads that may contain resources
|
|
15
|
-
* Should be called when the payload is no longer needed, especially in error cases
|
|
16
|
-
* @param payload The deserialized payload to clean up
|
|
17
|
-
*/
|
|
18
|
-
finalize?(payload: T): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* MIME type for this serialization format
|
|
21
|
-
*/
|
|
22
|
-
contentType: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Built-in JSON serializer/deserializer
|
|
26
|
-
* This implementation reads the entire stream into memory for JSON parsing
|
|
27
|
-
*/
|
|
28
|
-
declare class JsonTransport<T = unknown> implements Transport<T> {
|
|
29
|
-
readonly contentType = "application/json";
|
|
30
|
-
readonly replacer?: Parameters<typeof JSON.parse>[1];
|
|
31
|
-
readonly reviver?: Parameters<typeof JSON.parse>[1];
|
|
32
|
-
constructor(options?: {
|
|
33
|
-
replacer?: Parameters<typeof JSON.parse>[1];
|
|
34
|
-
reviver?: Parameters<typeof JSON.parse>[1];
|
|
35
|
-
});
|
|
36
|
-
serialize(value: T): Buffer;
|
|
37
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Built-in Buffer serializer/deserializer (reads entire stream into a Buffer)
|
|
41
|
-
*/
|
|
42
|
-
declare class BufferTransport implements Transport<Buffer> {
|
|
43
|
-
readonly contentType = "application/octet-stream";
|
|
44
|
-
serialize(value: Buffer): Buffer;
|
|
45
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<Buffer>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Stream serializer/deserializer (pass-through for streaming binary data)
|
|
49
|
-
* This is ideal for large payloads that don't need to be buffered in memory
|
|
50
|
-
*
|
|
51
|
-
* IMPORTANT: When using StreamTransport, you must call finalize(payload) when done
|
|
52
|
-
* processing the message to prevent resource leaks, especially in error cases.
|
|
53
|
-
* ConsumerGroup handles this automatically, but direct QueueClient usage requires manual cleanup.
|
|
54
|
-
*
|
|
55
|
-
* Example usage:
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const transport = new StreamTransport();
|
|
58
|
-
* try {
|
|
59
|
-
* for await (const message of client.receiveMessages(options, transport)) {
|
|
60
|
-
* // Process the stream...
|
|
61
|
-
* const reader = message.payload.getReader();
|
|
62
|
-
* // ... handle stream data
|
|
63
|
-
* }
|
|
64
|
-
* } catch (error) {
|
|
65
|
-
* // Cleanup is handled automatically by ConsumerGroup
|
|
66
|
-
* // or manually: await transport.finalize(message.payload);
|
|
67
|
-
* }
|
|
68
|
-
*/
|
|
69
|
-
declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
|
|
70
|
-
readonly contentType = "application/octet-stream";
|
|
71
|
-
serialize(value: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
|
|
72
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>>;
|
|
73
|
-
finalize(payload: ReadableStream<Uint8Array>): Promise<void>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Vercel Queue Service client types
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Shared options for publishing messages
|
|
82
|
-
*/
|
|
83
|
-
interface PublishOptions {
|
|
84
|
-
/**
|
|
85
|
-
* Unique key to prevent duplicate message submissions
|
|
86
|
-
* @default random UUID
|
|
87
|
-
*/
|
|
88
|
-
idempotencyKey?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Message retention time in seconds
|
|
91
|
-
* @default 86400 (24 hours)
|
|
92
|
-
* @min 60
|
|
93
|
-
* @max 86400
|
|
94
|
-
*/
|
|
95
|
-
retentionSeconds?: number;
|
|
96
|
-
/**
|
|
97
|
-
* Explicit deployment identifier to include in the `Vqs-Deployment-Id` header
|
|
98
|
-
* If provided, this takes precedence over any value from the environment
|
|
99
|
-
*/
|
|
100
|
-
deploymentId?: string;
|
|
101
|
-
}
|
|
102
|
-
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
103
|
-
/**
|
|
104
|
-
* The queue name to send the message to
|
|
105
|
-
*/
|
|
106
|
-
queueName: string;
|
|
107
|
-
/**
|
|
108
|
-
* The message payload
|
|
109
|
-
*/
|
|
110
|
-
payload: T;
|
|
111
|
-
}
|
|
112
|
-
interface SendMessageResponse {
|
|
113
|
-
/**
|
|
114
|
-
* The generated message ID
|
|
115
|
-
*/
|
|
116
|
-
messageId: string;
|
|
117
|
-
}
|
|
118
|
-
interface Message<T = unknown> {
|
|
119
|
-
/**
|
|
120
|
-
* The message ID
|
|
121
|
-
*/
|
|
122
|
-
messageId: string;
|
|
123
|
-
/**
|
|
124
|
-
* The deserialized message payload
|
|
125
|
-
* Note: If using streaming transports, ensure proper cleanup by calling transport.finalize(payload)
|
|
126
|
-
* when done processing, especially in error cases
|
|
127
|
-
*/
|
|
128
|
-
payload: T;
|
|
129
|
-
/**
|
|
130
|
-
* Number of times this message has been delivered
|
|
131
|
-
*/
|
|
132
|
-
deliveryCount: number;
|
|
133
|
-
/**
|
|
134
|
-
* When the message was created
|
|
135
|
-
*/
|
|
136
|
-
createdAt: Date;
|
|
137
|
-
/**
|
|
138
|
-
* MIME type of the message content
|
|
139
|
-
*/
|
|
140
|
-
contentType: string;
|
|
141
|
-
/**
|
|
142
|
-
* Unique ticket for this message delivery (required for delete/patch operations)
|
|
143
|
-
*/
|
|
144
|
-
ticket: string;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Result indicating the message should be timed out for retry later
|
|
148
|
-
*/
|
|
149
|
-
interface MessageTimeoutResult {
|
|
150
|
-
/**
|
|
151
|
-
* Time in seconds before the message becomes visible again
|
|
152
|
-
*/
|
|
153
|
-
timeoutSeconds: number;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Result returned by message handlers
|
|
157
|
-
*/
|
|
158
|
-
type MessageHandlerResult = void | MessageTimeoutResult;
|
|
159
|
-
/**
|
|
160
|
-
* Message metadata provided to handlers
|
|
161
|
-
*/
|
|
162
|
-
interface MessageMetadata {
|
|
163
|
-
messageId: string;
|
|
164
|
-
deliveryCount: number;
|
|
165
|
-
createdAt: Date;
|
|
166
|
-
topicName: string;
|
|
167
|
-
consumerGroup: string;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Message handler function type
|
|
171
|
-
*/
|
|
172
|
-
type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
|
|
173
|
-
/**
|
|
174
|
-
* Options for creating a ConsumerGroup instance
|
|
175
|
-
*/
|
|
176
|
-
interface ConsumerGroupOptions<T = unknown> {
|
|
177
|
-
/**
|
|
178
|
-
* Serializer/deserializer for the payload
|
|
179
|
-
* @default JsonTransport instance
|
|
180
|
-
*/
|
|
181
|
-
transport?: Transport<T>;
|
|
182
|
-
/**
|
|
183
|
-
* Time in seconds that messages will be invisible to other consumers
|
|
184
|
-
* @default 30
|
|
185
|
-
*/
|
|
186
|
-
visibilityTimeoutSeconds?: number;
|
|
187
|
-
/**
|
|
188
|
-
* How often to refresh the visibility timeout during processing (in seconds)
|
|
189
|
-
* @default 10
|
|
190
|
-
*/
|
|
191
|
-
refreshInterval?: number;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Error thrown when a message is not found (404)
|
|
195
|
-
*/
|
|
196
|
-
declare class MessageNotFoundError extends Error {
|
|
197
|
-
constructor(messageId: string);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Error thrown when a message is not available for processing (409)
|
|
201
|
-
* This can happen when the message is in the wrong state, already claimed, etc.
|
|
202
|
-
*/
|
|
203
|
-
declare class MessageNotAvailableError extends Error {
|
|
204
|
-
constructor(messageId: string, reason?: string);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Error thrown when message data is corrupted or can't be parsed
|
|
208
|
-
*/
|
|
209
|
-
declare class MessageCorruptedError extends Error {
|
|
210
|
-
constructor(messageId: string, reason: string);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Error thrown when there are no messages available in the queue (204)
|
|
214
|
-
*/
|
|
215
|
-
declare class QueueEmptyError extends Error {
|
|
216
|
-
constructor(queueName: string, consumerGroup: string);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Error thrown when a message is temporarily locked (423)
|
|
220
|
-
*/
|
|
221
|
-
declare class MessageLockedError extends Error {
|
|
222
|
-
readonly retryAfter?: number;
|
|
223
|
-
constructor(messageId: string, retryAfter?: number);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Error thrown when authentication fails (401)
|
|
227
|
-
*/
|
|
228
|
-
declare class UnauthorizedError extends Error {
|
|
229
|
-
constructor(message?: string);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Error thrown when access is forbidden (403)
|
|
233
|
-
*/
|
|
234
|
-
declare class ForbiddenError extends Error {
|
|
235
|
-
constructor(message?: string);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Error thrown for bad requests (400)
|
|
239
|
-
*/
|
|
240
|
-
declare class BadRequestError extends Error {
|
|
241
|
-
constructor(message: string);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Error thrown for internal server errors (500)
|
|
245
|
-
*/
|
|
246
|
-
declare class InternalServerError extends Error {
|
|
247
|
-
constructor(message?: string);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Error thrown when batch limit parameter is invalid
|
|
251
|
-
*/
|
|
252
|
-
declare class InvalidLimitError extends Error {
|
|
253
|
-
constructor(limit: number, min?: number, max?: number);
|
|
254
|
-
}
|
|
1
|
+
import { M as MessageHandler, C as ConsumerGroupOptions, P as PublishOptions, T as Transport } from './types-JvOenjfT.js';
|
|
2
|
+
export { a as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, b as InvalidLimitError, J as JsonTransport, g as Message, c as MessageCorruptedError, h as MessageHandlerResult, d as MessageLockedError, i as MessageMetadata, e as MessageNotAvailableError, f as MessageNotFoundError, j as MessageTimeoutResult, Q as QueueEmptyError, k as SendMessageOptions, l as SendMessageResponse, S as StreamTransport, U as UnauthorizedError } from './types-JvOenjfT.js';
|
|
255
3
|
|
|
256
4
|
/**
|
|
257
5
|
* Options for the consume method
|
|
@@ -408,4 +156,4 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
|
|
|
408
156
|
*/
|
|
409
157
|
declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
|
|
410
158
|
|
|
411
|
-
export {
|
|
159
|
+
export { MessageHandler, type ParsedCallbackRequest, PublishOptions, type ReceiveOptions, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
|
package/dist/pages.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { M as MessageHandler } from './types-JvOenjfT.mjs';
|
|
2
|
+
|
|
3
|
+
type CallbackHandlers = {
|
|
4
|
+
[topicName: string]: {
|
|
5
|
+
[consumerGroup: string]: MessageHandler;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
interface NextApiRequest {
|
|
9
|
+
method?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
headers: Record<string, string | string[] | undefined>;
|
|
12
|
+
body?: any;
|
|
13
|
+
on(event: "data", listener: (chunk: Buffer) => void): void;
|
|
14
|
+
on(event: "end", listener: () => void): void;
|
|
15
|
+
on(event: "error", listener: (err: Error) => void): void;
|
|
16
|
+
}
|
|
17
|
+
interface NextApiResponse {
|
|
18
|
+
status(statusCode: number): NextApiResponse;
|
|
19
|
+
setHeader(name: string, value: string): void;
|
|
20
|
+
json(data: any): void;
|
|
21
|
+
send(data: any): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Queue callback handler for Next.js Pages Router
|
|
25
|
+
*
|
|
26
|
+
* Automatically extracts queue information from CloudEvent format
|
|
27
|
+
* and routes to the appropriate handler based on topic and consumer group.
|
|
28
|
+
*
|
|
29
|
+
* @param handlers Object with topic-specific handlers organized by consumer groups
|
|
30
|
+
* @returns A Next.js Pages Router handler function
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // pages/api/queue.ts
|
|
35
|
+
* import { handleCallback } from "@vercel/queue/pages";
|
|
36
|
+
*
|
|
37
|
+
* export default handleCallback({
|
|
38
|
+
* "image-processing": {
|
|
39
|
+
* "compress": (message, metadata) => console.log("Compressing image", message),
|
|
40
|
+
* "resize": (message, metadata) => console.log("Resizing image", message),
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function handleCallback(handlers: CallbackHandlers): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
46
|
+
|
|
47
|
+
export { handleCallback };
|