@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.
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Serializer/Deserializer interface for message payloads
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
+ }
255
+
256
+ export { BufferTransport as B, type ConsumerGroupOptions as C, ForbiddenError as F, InternalServerError as I, JsonTransport as J, type MessageHandler as M, type PublishOptions as P, QueueEmptyError as Q, StreamTransport as S, type Transport as T, UnauthorizedError as U, BadRequestError as a, InvalidLimitError as b, MessageCorruptedError as c, MessageLockedError as d, MessageNotAvailableError as e, MessageNotFoundError as f, type Message as g, type MessageHandlerResult as h, type MessageMetadata as i, type MessageTimeoutResult as j, type SendMessageOptions as k, type SendMessageResponse as l };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/queue",
3
- "version": "0.0.0-alpha.29",
3
+ "version": "0.0.0-alpha.30",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,13 +14,23 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": {
17
- "types": "./dist/index.d.ts",
17
+ "types": "./dist/index.d.mts",
18
18
  "default": "./dist/index.mjs"
19
19
  },
20
20
  "require": {
21
21
  "types": "./dist/index.d.ts",
22
22
  "default": "./dist/index.js"
23
23
  }
24
+ },
25
+ "./pages": {
26
+ "import": {
27
+ "types": "./dist/pages.d.mts",
28
+ "default": "./dist/pages.mjs"
29
+ },
30
+ "require": {
31
+ "types": "./dist/pages.d.ts",
32
+ "default": "./dist/pages.js"
33
+ }
24
34
  }
25
35
  },
26
36
  "files": [