import connect from "connect";
import { QuirrelClient, } from "./client";
import bodyParser from "body-parser";
export function Queue(route, handler, options) {
    const quirrel = new QuirrelClient({
        route,
        handler,
        options,
    });
    const server = connect();
    server.use(bodyParser.text());
    server.use(async (req, res, next) => {
        if (req.url !== "/" + route) {
            return next();
        }
        const { body, status, headers } = await quirrel.respondTo(req.body, req.headers);
        res.statusCode = status;
        for (const [header, value] of Object.entries(headers)) {
            res.setHeader(header, value);
        }
        res.write(body);
        res.end();
    });
    server.enqueue = (payload, options) => quirrel.enqueue(payload, options);
    server.enqueueMany = (jobs) => quirrel.enqueueMany(jobs);
    server.get = () => quirrel.get();
    server.delete = (id) => quirrel.delete(id);
    server.getById = (id) => quirrel.getById(id);
    server.invoke = (id) => quirrel.invoke(id);
    return server;
}
export function CronJob(route, cronSchedule, handler, options) {
    return Queue(route, handler, options);
}
//# sourceMappingURL=connect.js.map