Serverless MongoDB. What are you ... mongonna do about it?
naming things is hard
Atlas App Service leaves a lot to be desired. If you're using Mongo, you just kind of wanted to use Mongo the way it was intended!
ES6 Proxies. And some TypeScript magic. Chain it all together, tell Mongonna about your Mongo Client, because it's a peer dependency and its your types. We're just the chaining and RPC call.
const client = new MongonnaClient<MongoClient>( // <= Tell us your MongoClient typings
"http://localhost:3000", // <= who should we talk to
"SUPER_SECRET_SERVER_1" // <= this can be an opaque identifier or real mongo URL
);
await client.db("foo").collection("bar").find({ a: 1 }).toArray();
// ^ ^ ^ ^
// \ | | /
// \ \ | /
// Every 👏🏻 Call 👏🏻 Is 👏🏻 Typed
It's up to you. You'll get a payload at your url containing
interface MongonnaRequest {
url: string; // <= self referentia>
mongoUrl: string; // <= That identifier from above or a full mongo URL
options: MongonnaClientOptions; // <= The client options object
chain: MongonnaStack; // <= The chain of calls to execute
}
You can then call applyMongonna
wih your client & chain object, and we reflect those calls onto the MongoClient
you give us. The resulting object contains the data
result from the call, or a serialized error
object that can be returned. Send the whole chunk back as JSON!
const { data, error } = await applyMongonna(client, chain);
sendJson(200, { data, error }); // status code 200. The call worked, errors will be rethrown locally