mongodb-runner 4.10.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,253 +1,68 @@
1
- # mongodb-runner [![][npm_img]][npm_url] [![][travis_img]][travis_url] [![][appveyor_img]][appveyor_url]
1
+ # mongodb-runner
2
2
 
3
- > Easily install and run MongoDB to test your code against it.
3
+ Helper for spinning up MongoDB servers and clusters for testing.
4
4
 
5
- ## Table of Contents
5
+ ## Example usage
6
6
 
7
- - [Introduction](#introduction)
8
- - [How to play with MongoDB](#how-to-play-with-mongodb)
9
- - [Debugging](#debugging)
10
- - [Configuration](#configuration)
11
- - [CLI Usage](#cli)
12
- - [TravisCI Integration](#travisci)
13
- - [Mocha Integration](#mocha)
7
+ > Note: Version 5 of mongodb-runner is a full re-write. Many things work
8
+ > differently in version 5 and above.
14
9
 
15
-
16
- ## Introduction
17
-
18
- This is a tool I wrote for a node app using MongoDB that I was working on. I wanted other contributors to have the database, MongoDB, just work without any extra steps once they cloned the repo and installed app dependencies.
19
-
20
- Then I wanted to be able to test using different versions and configurations of mongo. This tool allowed me to test new releases and configurations of mongo before changing anything in our app servers on AWS.
21
-
22
- :warning: For experiments only: Please do not use this tool in production or for anything that considers data storage to be 100% emphemeral.
23
-
24
- ## How to play with MongoDB
25
-
26
- ```javascript
27
- npm install -g mongodb-runner;
28
- mongodb-runner start; # downloads mongodb and starts locally
29
- mongo; # Shell opens connected to mongodb://localhost:27017
10
+ ```bash
11
+ $ npx mongodb-runner start -t sharded
12
+ $ npx mongodb-runner start -t replset -- --port 27017
13
+ $ npx mongodb-runner start -t replset -- --setParameter allowDiskUseByDefault=true
14
+ $ npx mongodb-runner stop --all
15
+ $ npx mongodb-runner exec -t standalone -- sh -c 'mongosh $MONGODB_URI'
16
+ $ npx mongodb-runner exec -t standalone -- --setParameter allowDiskUseByDefault=true -- sh -c 'mongosh $MONGODB_URI'
30
17
  ```
31
18
 
32
- ## Debugging
33
-
34
- `mongodb-runner` uses the [`debug`](https://npm.im/debug) module so if something isn't working correctly, set the `DEBUG` environment variable to `DEBUG=mongodb-*` for lots of helpful messages.
35
-
36
- ## Configuration
37
-
38
- ### version
39
-
40
- The latest stable version of MongoDB will automatically be downloaded and installed by default when `start` is run.
41
- <!-- TODO: lucas: Merge version-manager info on stable|unstable|semver. -->
42
-
43
- [Default: `stable`]
44
-
45
- ### port
46
-
47
- The port MongoDB will be accessible locally on.
48
-
49
- [Default: `27017`]
50
-
51
- ### dbpath
52
-
53
- The base path for data storage. [Default: `~/.mongodb/data/standalone`]
54
-
55
- ### logpath
56
-
57
- The base directory for data to be stored. [Default: `~/.mongodb/logs/standalone.log`]
58
-
59
- ### topology
60
-
61
- One of standalone, replicaset, or cluster [Default: `standalone`].
62
-
63
- ### replicaset options
64
-
65
- > only applicable when [`topology`](#topology) is `replicaset`
66
-
67
- #### arbiters
68
-
69
- The number of arbiter processes to start [Default: `0`].
70
-
71
- #### passives
72
-
73
- The number of passive processes to start [Default: `1`].
74
-
75
- #### secondaries
76
-
77
- How many secondary instances to start [Default: `2`].
78
-
79
- ### cluster options
80
-
81
- > only applicable when [`topology`](#topology) is `cluster`
82
-
83
- #### shards
84
-
85
- Number of shards in the cluster [Default: `2`].
86
-
87
- #### routers
88
-
89
- Number of router processes to start [Default: `2`].
90
-
91
- #### configs
92
-
93
- Number of config server processes to start [Default: `1`].
94
-
95
- #### routerPort
96
-
97
- Port number to start incrementing from when starting routers [Default `50000`].
98
-
99
- #### shardPort
100
-
101
- Port number to start incrementing from when starting shard members [Default `31000`].
102
-
103
- #### configPort
104
-
105
- Port number to start incrementing from when starting config servers [Default `35000`].
106
-
107
- ### Using Environment Variables
108
-
109
- | Option | Environment Variable |
110
- | :--- | :--- |
111
- |[`version`](#version) | MONGODB_VERSION |
112
- |[`port`](#port) | MONGODB_PORT |
113
- |[`topology`](#topology) | MONGODB_TOPOLOGY |
114
- |[`arbiters`](#arbiters) | MONGODB_ARBITERS |
115
- |[`secondaries`](#secondaries) | MONGODB_SECONDARIES |
116
- |[`passives`](#passives) | MONGODB_PASSIVES |
117
- |[`shards`](#shards) | MONGODB_SHARDS |
118
- |[`routers`](#routers) | MONGODB_ROUTERS |
119
- |[`configs`](#configs) | MONGODB_CONFIGS |
120
- |[`shards_port`](#shards_port) | MONGODB_SHARDS_PORT |
121
- |[`configs_port`](#configs_port) | MONGODB_CONFIGS_PORT |
122
- |[`arbiters`](#arbiters) | MONGODB_ARBITERS |
123
- |[`secondaries`](#secondaries) | MONGODB_SECONDARIES |
124
- |[`passives`](#passives) | MONGODB_PASSIVES |
125
-
126
- ## CLI
19
+ ## Options
127
20
 
128
21
  ```
129
- Usage: mongodb-runner <start|stop> [options]
22
+ mongodb-runner <command>
130
23
 
131
- Start/stop mongodb for testing.
24
+ Commands:
25
+ mongodb-runner start Start a MongoDB instance
26
+ mongodb-runner stop Stop a MongoDB instance
27
+ mongodb-runner ls List currently running MongoDB instances
28
+ mongodb-runner exec Run a process with a MongoDB instance (as MONGODB_URI
29
+ env var)
132
30
 
133
31
  Options:
134
- --topology=<topology> One of standalone, replicaset, or cluster [Default: `standalone`].
135
- --pidpath=<pidpath> Where to put pid files [Default: `~/.mongodb/pids`].
136
- --bin=<path> Path to mongod|mongos binary [Default: `which mongod|mongos`].
137
-
138
- Options depending on `--topology`:
139
- --topology=standalone
140
- --name=<name> The replSet name [Default: `my-standalone`].
141
- --port=<port> Port to start mongod on [Default: `27017`].
142
- --dbpath=<dbpath> Where to put the data [Default: `~/.mongodb/data/[standalone]`]
143
- --logpath=<logpath> [Default: `~/.mongodb/#{name}.log`]
144
-
145
- --topology=replicaset
146
- --name=<name> The replSet name [Default: `my-replicaset`].
147
- --port=<port> The starting port to use for mongod instances [Default: `31000`].
148
- --dbpath=<dbpath> [Default: `~/.mongodb/data/#{name}-#{instance_id}`]
149
- --logpath=<logpath> [Default: `~/.mongodb/#{name}.log/#{instance_id}.log`]
150
- --arbiters=<n> How many arbiters to start [Default: `0`].
151
- --passives=<n> How many passive instances to start [Default: `1`].
152
- --secondaries=<n> How many secondary instances to start [Default: `2`]. Maps to `secondaries` option.
153
-
154
- --topology=cluster
155
- --shards=<n> Number of shards in the cluster [Default: `2`].
156
- --routers=<n> Number of router instances [Default: `2`].
157
- --configs=<n> Number of config servers [Default: `1`].
158
- --routerPort=<port> Port number to start incrementing from when starting routers [Default `50000`].
159
- --port=<port> Port number to start incrementing from when starting shard members [Default `31000`].
160
- --configPort=<port> Port number to start incrementing from when starting shard members [Default `35000`].
161
-
162
- Environment Variables:
163
- MONGODB_VERSION What version of MongoDB should be installed and available [Default: `stable`]
164
- MONGODB_TOPOLOGY See `--topology`
165
- MONGODB_PORT See `--port`
166
- MONGODB_TOPOLOGY See `topology`
167
- MONGODB_ARBITERS See `arbiters`
168
- MONGODB_SECONDARIES See `secondaries`
169
- MONGODB_PASSIVES See `passives`
170
- MONGODB_SHARDS See `--shards`
171
- MONGODB_ROUTERS See `--routers`
172
- MONGODB_CONFIGS See `--configs`
173
- MONGODB_SHARDS_PORT See `--shardPort`
174
- MONGODB_CONFIGS_PORT See `--configPort`
175
- MONGODB_ARBITERS See `--arbiters`
176
- MONGODB_SECONDARIES See `--secondaries`
177
- MONGODB_PASSIVES See `--passives`
32
+ -t, --topology Select a topology type
33
+ [choices: "standalone", "replset", "sharded"] [default: "standalone"]
34
+ --arbiters number of arbiter nodes for each replica set [number]
35
+ --secondaries number of secondaries for each replica set [number]
36
+ --shards number of shards for sharded clusters [number]
37
+ --version MongoDB server version to use [string]
38
+ --logDir Directory to store server log files in [string]
39
+ --binDir Directory containing mongod/mongos binaries [string]
40
+ --tmpDir Directory for temporary files [string] [default: "/tmp"]
41
+ --runnerDir Directory for storing cluster metadata
42
+ [string] [default: "/home/addaleax/.mongodb/runner2"]
43
+ --docker Docker image name to run server instances under [string]
44
+ --id ID to save the cluster metadata under [string]
45
+ --all for `stop`: stop all clusters [boolean]
46
+ --debug Enable debug output [boolean]
47
+ --help Show help [boolean]
178
48
  ```
179
49
 
180
- ## TravisCI
50
+ ## Programmatic use
181
51
 
182
- Modify your `package.json` to start and stop MongoDB before and after your tests
183
- automatically when you run `npm test`:
184
-
185
- ```json
186
- {
187
- "scripts": {
188
- "pretest": "mongodb-runner start",
189
- "test": "mocha",
190
- "posttest": "mongodb-runner stop"
191
- }
192
- }
193
- ```
194
-
195
- Update your `.travis.yml` to run your tests against the full version + topology matrix:
196
-
197
- ```yaml
198
- language: node_js
199
- cache:
200
- directories:
201
- - node_modules
202
- env:
203
- - MONGODB_VERSION=^3.6.0 MONGODB_TOPOLOGY=standalone
204
- - MONGODB_VERSION=stable MONGODB_TOPOLOGY=standalone
205
- - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=standalone
206
- - MONGODB_VERSION=^3.6.0 MONGODB_TOPOLOGY=replicaset
207
- - MONGODB_VERSION=stable MONGODB_TOPOLOGY=replicaset
208
- - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=replicaset
209
- - MONGODB_VERSION=^3.6.0 MONGODB_TOPOLOGY=cluster
210
- - MONGODB_VERSION=stable MONGODB_TOPOLOGY=cluster
211
- - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=cluster
212
52
  ```
53
+ import { MongoCluster } from 'mongodb-runner';
213
54
 
214
- And :tada: Now you're fully covered for all of those all of those edge cases the full
215
- version + topology matrix can present!
216
-
217
- ### Mocha
218
-
219
- Mocha before/after hooks make writing tests for code that depends on MongoDB insanely simple:
220
-
221
- ```javascript
222
- describe('my app', function() {
223
- before(require('mongodb-runner/mocha/before'));
224
- after(require('mongodb-runner/mocha/after'));
225
- it('should connect', function(done) {
226
- require('mongodb').connect('mongodb://localhost:27017/', done);
227
- });
55
+ const cluster = await MongoCluster.start({
56
+ topology: 'standalone'
228
57
  });
229
- ```
230
-
231
- Global hooks are also supported. Add the following to a new file called `test/mongodb.js`:
232
-
233
- ```javascript
234
- before(require('mongodb-runner/mocha/before'));
235
- after(require('mongodb-runner/mocha/after'));
236
- ```
237
58
 
238
- And then just require it:
239
-
240
- ```
241
- mocha --require test/mongodb.js test/*.test.js
59
+ try {
60
+ console.log(cluster.connectionString);
61
+ } finally {
62
+ await cluster.close();
63
+ }
242
64
  ```
243
65
 
244
66
  ## License
245
67
 
246
68
  Apache 2.0
247
-
248
- [travis_img]: https://img.shields.io/travis/mongodb-js/runner.svg?style=flat-square
249
- [travis_url]: https://travis-ci.org/mongodb-js/runner
250
- [npm_img]: https://img.shields.io/npm/v/mongodb-runner.svg
251
- [npm_url]: https://www.npmjs.org/package/mongodb-runner
252
- [appveyor_img]: https://ci.appveyor.com/api/projects/status/w3guhkp628hwwpjg?svg=true
253
- [appveyor_url]: https://ci.appveyor.com/project/imlucas/runner
package/bin/runner.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ require('../dist/cli.js');
@@ -0,0 +1,5 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod;
4
+ export const MongoCluster = mod.MongoCluster;
5
+ export const MongoServer = mod.MongoServer;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const yargs_1 = __importDefault(require("yargs"));
7
+ const mongocluster_1 = require("./mongocluster");
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = require("fs");
11
+ const mongodb_1 = require("mongodb");
12
+ const child_process_1 = require("child_process");
13
+ const debug_1 = __importDefault(require("debug"));
14
+ const events_1 = require("events");
15
+ (async function () {
16
+ var _a;
17
+ const defaultRunnerDir = path_1.default.join(os_1.default.homedir(), '.mongodb', 'runner2');
18
+ const argv = await yargs_1.default
19
+ .version(false)
20
+ .scriptName('mongodb-runner')
21
+ .option('topology', {
22
+ alias: 't',
23
+ choices: ['standalone', 'replset', 'sharded'],
24
+ default: 'standalone',
25
+ describe: 'Select a topology type',
26
+ })
27
+ .option('arbiters', {
28
+ type: 'number',
29
+ describe: 'number of arbiter nodes for each replica set',
30
+ })
31
+ .option('secondaries', {
32
+ type: 'number',
33
+ describe: 'number of secondaries for each replica set',
34
+ })
35
+ .option('shards', {
36
+ type: 'number',
37
+ describe: 'number of shards for sharded clusters',
38
+ })
39
+ .option('version', {
40
+ type: 'string',
41
+ describe: 'MongoDB server version to use',
42
+ })
43
+ .option('logDir', {
44
+ type: 'string',
45
+ describe: 'Directory to store server log files in',
46
+ })
47
+ .option('binDir', {
48
+ type: 'string',
49
+ describe: 'Directory containing mongod/mongos binaries',
50
+ })
51
+ .option('tmpDir', {
52
+ type: 'string',
53
+ default: os_1.default.tmpdir(),
54
+ describe: 'Directory for temporary files',
55
+ })
56
+ .option('runnerDir', {
57
+ type: 'string',
58
+ default: defaultRunnerDir,
59
+ describe: 'Directory for storing cluster metadata',
60
+ })
61
+ .option('docker', {
62
+ type: 'string',
63
+ describe: 'Docker image name to run server instances under',
64
+ })
65
+ .option('id', {
66
+ type: 'string',
67
+ describe: 'ID to save the cluster metadata under',
68
+ })
69
+ .option('all', {
70
+ type: 'boolean',
71
+ describe: 'for `stop`: stop all clusters',
72
+ })
73
+ .option('debug', { type: 'boolean', describe: 'Enable debug output' })
74
+ .command('start', 'Start a MongoDB instance')
75
+ .command('stop', 'Stop a MongoDB instance')
76
+ .command('ls', 'List currently running MongoDB instances')
77
+ .command('exec', 'Run a process with a MongoDB instance (as MONGODB_URI env var)')
78
+ .demandCommand(1, 'A command needs to be provided')
79
+ .help().argv;
80
+ const [command, ...args] = argv._.map(String);
81
+ if (argv.debug) {
82
+ debug_1.default.enable('mongodb-runner');
83
+ }
84
+ async function start() {
85
+ const id = argv.id || new mongodb_1.BSON.UUID().toHexString();
86
+ if (!/^[a-zA-Z0-9_-]+$/.test(id)) {
87
+ throw new Error(`ID '${id}' contains non-alphanumeric characters`);
88
+ }
89
+ await fs_1.promises.mkdir(argv.runnerDir, { recursive: true });
90
+ const cluster = await mongocluster_1.MongoCluster.start({
91
+ ...argv,
92
+ args,
93
+ });
94
+ const serialized = await cluster.serialize();
95
+ const { connectionString } = cluster;
96
+ await fs_1.promises.writeFile(path_1.default.join(argv.runnerDir, `m-${id}.json`), JSON.stringify({ id, serialized, connectionString }));
97
+ console.log(`Server started and running at ${connectionString}`);
98
+ console.log('Run the following command to stop the instance:');
99
+ console.log(`${argv.$0} stop --id=${id}` +
100
+ (argv.runnerDir !== defaultRunnerDir
101
+ ? `--runnerDir=${argv.runnerDir}`
102
+ : ''));
103
+ cluster.unref();
104
+ }
105
+ async function* instances() {
106
+ for await (const { name } of await fs_1.promises.opendir(argv.runnerDir)) {
107
+ if (name.startsWith('m-') && name.endsWith('.json')) {
108
+ try {
109
+ const filepath = path_1.default.join(argv.runnerDir, name);
110
+ const stored = JSON.parse(await fs_1.promises.readFile(filepath, 'utf8'));
111
+ yield { ...stored, filepath };
112
+ }
113
+ catch (_a) {
114
+ }
115
+ }
116
+ }
117
+ }
118
+ async function stop() {
119
+ if (!argv.id && !argv.all) {
120
+ throw new Error('Need --id or --all to know which server to stop');
121
+ }
122
+ const toStop = [];
123
+ for await (const instance of instances()) {
124
+ if (instance.id === argv.id || argv.all)
125
+ toStop.push(instance);
126
+ }
127
+ await Promise.all(toStop.map(async ({ id, filepath, serialized, connectionString }) => {
128
+ await (await mongocluster_1.MongoCluster.deserialize(serialized)).close();
129
+ await fs_1.promises.rm(filepath);
130
+ console.log(`Stopped cluster '${id}' (was running at '${connectionString}')`);
131
+ }));
132
+ }
133
+ async function ls() {
134
+ for await (const { id, connectionString } of instances()) {
135
+ console.log(`${id}: ${connectionString}`);
136
+ }
137
+ }
138
+ async function exec() {
139
+ let mongodArgs;
140
+ let execArgs;
141
+ const doubleDashIndex = args.indexOf('--');
142
+ if (doubleDashIndex !== -1) {
143
+ mongodArgs = args.slice(0, doubleDashIndex);
144
+ execArgs = args.slice(doubleDashIndex + 1);
145
+ }
146
+ else {
147
+ mongodArgs = [];
148
+ execArgs = args;
149
+ }
150
+ const cluster = await mongocluster_1.MongoCluster.start({
151
+ ...argv,
152
+ args: mongodArgs,
153
+ });
154
+ try {
155
+ const [prog, ...progArgs] = execArgs;
156
+ const child = (0, child_process_1.spawn)(prog, progArgs, {
157
+ stdio: 'inherit',
158
+ env: {
159
+ ...process.env,
160
+ MONGODB_URI: cluster.connectionString,
161
+ MONGODB_URL: cluster.connectionString,
162
+ MONGODB_HOSTPORT: cluster.hostport,
163
+ },
164
+ });
165
+ [process.exitCode] = await (0, events_1.once)(child, 'exit');
166
+ }
167
+ finally {
168
+ await cluster.close();
169
+ }
170
+ }
171
+ async function unknown() {
172
+ throw new Error(`Unknown command: ${command}. See '${argv.$0} --help' for more information.`);
173
+ }
174
+ await ((_a = { start, stop, exec, ls }[command]) !== null && _a !== void 0 ? _a : unknown)();
175
+ })().catch((err) => {
176
+ process.nextTick(() => {
177
+ throw err;
178
+ });
179
+ });
180
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,iDAA8C;AAC9C,4CAAoB;AACpB,gDAAwB;AACxB,2BAAoC;AACpC,qCAA+B;AAC/B,iDAAsC;AACtC,kDAAgC;AAChC,mCAA8B;AAS9B,CAAC,KAAK;;IACJ,MAAM,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAExE,MAAM,IAAI,GAAG,MAAM,eAAK;SACrB,OAAO,CAAC,KAAK,C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
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoCluster = exports.MongoServer = void 0;
4
+ var mongoserver_1 = require("./mongoserver");
5
+ Object.defineProperty(exports, "MongoServer", { enumerable: true, get: function () { return mongoserver_1.MongoServer; } });
6
+ var mongocluster_1 = require("./mongocluster");
7
+ Object.defineProperty(exports, "MongoCluster", { enumerable: true, get: function () { return mongocluster_1.MongoCluster; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAgE;AAAvD,0GAAA,WAAW,OAAA;AAEpB,+CAAmE;AAA1D,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,30 @@
1
+ import type { MongoServerOptions } from './mongoserver';
2
+ import type { DownloadOptions } from '@mongodb-js/mongodb-downloader';
3
+ import { MongoClient } from 'mongodb';
4
+ export interface MongoClusterOptions extends Pick<MongoServerOptions, 'logDir' | 'tmpDir' | 'args' | 'binDir' | 'docker'> {
5
+ topology: 'standalone' | 'replset' | 'sharded';
6
+ arbiters?: number;
7
+ secondaries?: number;
8
+ shards?: number;
9
+ version?: string;
10
+ downloadOptions?: DownloadOptions;
11
+ }
12
+ export declare class MongoCluster {
13
+ private topology;
14
+ private replSetName?;
15
+ private servers;
16
+ private shards;
17
+ private constructor();
18
+ serialize(): unknown;
19
+ static deserialize(serialized: any): Promise<MongoCluster>;
20
+ get hostport(): string;
21
+ get connectionString(): string;
22
+ get serverVersion(): string;
23
+ get serverVariant(): 'enterprise' | 'community';
24
+ static start({ ...options }: MongoClusterOptions): Promise<MongoCluster>;
25
+ close(): Promise<void>;
26
+ withClient<Fn extends (client: MongoClient) => any>(fn: Fn): Promise<ReturnType<Fn>>;
27
+ ref(): void;
28
+ unref(): void;
29
+ }
30
+ //# sourceMappingURL=mongocluster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongocluster.d.ts","sourceRoot":"","sources":["../src/mongocluster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,kBAAkB,EAClB,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CACnD;IACD,QAAQ,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAiD;IACjE,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAsB;IAEpC,OAAO;IAIP,SAAS,IAAI,OAAO;WASP,WAAW,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAahE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,gBAAgB,IAAI,MAAM,CAI7B;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,aAAa,IAAI,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