Hey guys, I'm working on something and I was wondering what you all thought of this general design? Its for a sort of IaC thing
import { api, database, bucket, queue, job } from "@launchd/edge";
const db = database("main");
const uploads = bucket("uploads");
const emails = queue("emails");
export const createPost = api("/posts", { method: "POST" }, async (req) => {
const post = await db.post.create({
title: req.body.title,
body: req.body.body,
});
await uploads.put(`posts/${post.id}.json`, JSON.stringify(post));
await emails.send({ type: "post.created", postId: post.id });
return post;
});
export const emailSender = watcher(emails, (event) => {
if(event.type == "post.created"){
console.log(event.postId)
}
})
export const cleanup = job("cleanup", { every: "1h" }, async () => {
await db.post.deleteMany({ where: { archived: true } });
});