import { action, createContext, suspend } from "effection";
const ResponseContext = createContext("revolutions.httpResponse");
export function* respondNotFound() {
    let respond = yield* ResponseContext.expect();
    let response = new Response("Not Found", {
        status: 404,
        statusText: "Not Found",
    });
    respond(response);
    yield* suspend();
    throw new Error("This code is unreachable, but TypeScript don't know.");
}
export function* respondRedirect(url, options = {}) {
    let status = options.permanent ? 308 : 307;
    let respond = yield* ResponseContext.expect();
    respond(Response.redirect(url, status));
    yield* suspend();
    throw new Error("This code is unreachable, but TypeScript don't know.");
}
export function httpResponsesMiddleware() {
    return function* httpResponses(request, next) {
        try {
            return yield* action(function* (resolve) {
                yield* ResponseContext.set(resolve);
                resolve(yield* next(request));
            });
        }
        catch (error) {
            return new Response(error.stack, {
                status: 500,
                statusText: "Internal Server Error",
            });
        }
    };
}
//# sourceMappingURL=http-responses.js.map