@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,47 @@
1
+ import { M as MessageHandler } from './types-JvOenjfT.js';
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 };