Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support spinning up in-memory mongo server for local development #51

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__hyper__
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,44 @@ export default {
create `mod.js`

```js
import core from 'https://raw.githubusercontent.com/hyper63/hyper/hyper%40v4.1.0/packages/core/mod.ts'
import core from 'https://raw.githubusercontent.com/hyper63/hyper/hyper%40v4.3.2/packages/core/mod.ts'
import config from './hyper.config.js'

core(config)
```

### MongoDB In-Memory

This adapter supports dynamically starting a local MongoDB server, running in memory. This is a
great option for running a hyper Server locally, without needing to also spin up MongoDB locally
(this what [hyper-nano](https://github.com/hyper63/hyper/tree/main/images/nano) is doing underneath
the hood).

To start a local MongoDB server, simply pass the `dir` option to the adapter. You can also specify
`dirVersion` to specify the version of MongoDB to spin up locally.

```js
import { default as mongo } from 'https://raw.githubusercontent.com/hyper63/hyper-adapter-mongodb/{TAG}/mod.ts'

export default {
app: express,
adapter: [
{
port: 'data',
plugins: [mongo({ dir: '__hyper__', dirVersion: '7.0.4' })],
},
],
}
```

The adapter will dynamically download the corresponding MongoDB binary, start it, then generate a
connection string that the adapter will use to connect to it.

> The MongoDB binary is downloaded and cached in `dir`, if it does not already exist. This may take
> some time the first startup, but then is fast after caching. MongoDB data is stored in
> `{dir}/data`. The binary plus the internal MongoDB data can typically require a non-trivial amount
> of disk, around 500MB.

## Installation

This is a Deno module available to import from Github via Git Tags
Expand Down
22 changes: 22 additions & 0 deletions adapter.memory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mongo from './mod.ts'

import { suite } from './test/suite.ts'

Deno.test({
name: 'Mongo Adapter Test Suite - In-Memory',
fn: async (t) => {
const { client } = await mongo({ dir: '__hyper__', dirVersion: '7.0.4' }).load()
await suite(t)(client, { shouldBaseLine: true })
},
/**
* The native client maintains TCP connections
* and timers, as part of connecting to Mongo,
*
* So we ignore sanitization of these resources
* and ops, when running tests with the NativeClient
*
* See https://deno.com/manual/basics/testing/sanitizers
*/
sanitizeOps: false,
sanitizeResources: false,
})
4 changes: 2 additions & 2 deletions adapter.native.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NativeClient } from './clients/native.ts'
import mongo from './mod.ts'

import { suite } from './test/suite.ts'

Expand All @@ -10,7 +10,7 @@ Deno.test({
throw new Error('MongoDB connection string is required at MONGO_URL')
}

const client = new NativeClient({ url })
const { client } = await mongo({ url }).load()
await suite(t)(client, { shouldBaseLine: true })
},
/**
Expand Down
Loading