mongonna
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Mongonna

Serverless MongoDB. What are you ... mongonna do about it?

naming things is hard

Why

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!

How

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

Receiving the RPC

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

Readme

Keywords

Package Sidebar

Install

npm i mongonna

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

32.6 kB

Total Files

8

Last publish

Collaborators

  • jakobo