diff --git a/README.md b/README.md index 7d874a7..cbf10b2 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ export const EmailQueue = Queue( } ); -export const POST = EmailQueue.handler; +export const POST = EmailQueue; ``` Up top, we're importing `Queue`, which is a function that we use to declare a new Queue and export it as default. diff --git a/src/next-app.test.ts b/src/next-app.test.ts index 1e26a39..c6592db 100644 --- a/src/next-app.test.ts +++ b/src/next-app.test.ts @@ -52,7 +52,7 @@ describe("next-app", () => { process.nextTick(resolve); }); - queueResponse = await queue.handler({ + queueResponse = await queue({ text: async () => body, headers: new Headers({ "x-zeplo-id": "foo", @@ -433,7 +433,7 @@ describe("next-app", () => { it("calls queue inline instead of waiting with mode=direct", async () => { fetchSpy.mockImplementation(async (input, { body, headers = {} } = {}) => { - queueResponse = await queue.handler({ + queueResponse = await queue({ text: async () => body, headers: new Headers({ ...(!("X-Zeplo-Id" in headers) diff --git a/src/next-app.ts b/src/next-app.ts index 4ba8888..e93d87f 100644 --- a/src/next-app.ts +++ b/src/next-app.ts @@ -11,10 +11,9 @@ export const Queue = ( ) => { const zeplo = ZeploClient({ handler, route, options }); - return { - enqueue: async (payload: Payload, options?: EnqueueOptions) => - zeplo.enqueue(payload, options), - handler: (async (req) => { + // eslint-disable-next-line fp/no-mutating-assign -- HACK + return Object.assign( + (async (req) => { const { status, body } = await zeplo.respondTo( await req.text(), Object.fromEntries(req.headers.entries()) @@ -28,5 +27,9 @@ export const Queue = ( { status } ); }) satisfies (req: NextRequest) => Promise>, - }; + { + enqueue: async (payload: Payload, options?: EnqueueOptions) => + zeplo.enqueue(payload, options), + } + ); };