mongodb-data-service 21.10.0 → 21.14.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.
Files changed (51) hide show
  1. package/README.md +7 -22
  2. package/lib/connect-mongo-client.d.ts +11 -0
  3. package/lib/connect-mongo-client.js +88 -0
  4. package/lib/connect-mongo-client.js.map +1 -0
  5. package/lib/connect.js +2 -15
  6. package/lib/connect.js.map +1 -1
  7. package/lib/connection-info.d.ts +12 -0
  8. package/lib/connection-info.js +3 -0
  9. package/lib/connection-info.js.map +1 -0
  10. package/lib/connection-options.d.ts +2 -10
  11. package/lib/connection-secrets.d.ts +13 -0
  12. package/lib/connection-secrets.js +96 -0
  13. package/lib/connection-secrets.js.map +1 -0
  14. package/lib/connection-storage.d.ts +6 -0
  15. package/lib/connection-storage.js +45 -0
  16. package/lib/connection-storage.js.map +1 -0
  17. package/lib/connection-title.d.ts +2 -0
  18. package/lib/connection-title.js +25 -0
  19. package/lib/connection-title.js.map +1 -0
  20. package/lib/data-service.d.ts +62 -18
  21. package/lib/data-service.js +784 -75
  22. package/lib/data-service.js.map +1 -1
  23. package/lib/index.d.ts +8 -1
  24. package/lib/index.js +15 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/instance-detail-helper.d.ts +78 -32
  27. package/lib/instance-detail-helper.js +144 -433
  28. package/lib/instance-detail-helper.js.map +1 -1
  29. package/lib/{legacy-connection-model.d.ts → legacy/legacy-connection-model.d.ts} +25 -8
  30. package/lib/legacy/legacy-connection-model.js +203 -0
  31. package/lib/legacy/legacy-connection-model.js.map +1 -0
  32. package/lib/redact.d.ts +4 -1
  33. package/lib/redact.js +23 -11
  34. package/lib/redact.js.map +1 -1
  35. package/lib/run-command.d.ts +209 -0
  36. package/lib/run-command.js +11 -0
  37. package/lib/run-command.js.map +1 -0
  38. package/lib/ssh-tunnel.d.ts +5 -0
  39. package/lib/ssh-tunnel.js +73 -0
  40. package/lib/ssh-tunnel.js.map +1 -0
  41. package/lib/types.d.ts +2 -95
  42. package/package.json +26 -22
  43. package/lib/.esm-wrapper.mjs +0 -3
  44. package/lib/legacy-connect.d.ts +0 -7
  45. package/lib/legacy-connect.js +0 -97
  46. package/lib/legacy-connect.js.map +0 -1
  47. package/lib/legacy-connection-model.js +0 -62
  48. package/lib/legacy-connection-model.js.map +0 -1
  49. package/lib/native-client.d.ts +0 -92
  50. package/lib/native-client.js +0 -640
  51. package/lib/native-client.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mongodb-data-service [![][workflow_img]][workflow_url] [![][npm_img]][npm_url] [![][dependabot_img]][dependabot_url]
2
2
 
3
- > MongoDB Data Service: an API on top of (currently) the [MongoDB Node Driver][driver] and (some day) [mongodb-scope-client][scope-client].
3
+ > MongoDB Data Service: an API on top of the [MongoDB Node Driver][driver]
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,28 +10,16 @@ npm install --save mongodb-data-service
10
10
 
11
11
  ## Usage
12
12
 
13
- ### Instantiating the service.
13
+ ### Creating a new service instance
14
14
 
15
15
  ```javascript
16
- const Connection = require('mongodb-connection-model');
17
- const DataService = require('mongodb-data-service');
18
-
19
- var service = new DataService(
20
- new Connection({
21
- hostname: '127.0.0.1',
22
- port: 27018,
23
- ns: 'data-service',
24
- })
25
- );
26
- ```
27
-
28
- ### Connecting to the server.
16
+ const { connect } = require('mongodb-data-service');
29
17
 
30
- Once the service is ready, it will also emit a `readable` event.
18
+ // ...
31
19
 
32
- ```javascript
33
- service.connect((err) => assert.equal(null, err)})
34
- .on('readable', () => console.log('Connected!'));
20
+ const service = await connect({
21
+ driverUrl: 'mongodb://localhost:27018/data-service',
22
+ });
35
23
  ```
36
24
 
37
25
  ### API
@@ -148,13 +136,10 @@ service.sample('database.collection', {});
148
136
  npm test
149
137
  ```
150
138
 
151
- All tests in an electron renderer process thanks to [electron-mocha](https://npm.im/electron-mocha).
152
-
153
139
  [workflow_img]: https://github.com/mongodb-js/data-service/workflows/Check%20and%20Test/badge.svg?event=push
154
140
  [workflow_url]: https://github.com/mongodb-js/data-service/actions?query=workflow%3A%22Check+and+Test%22
155
141
  [npm_img]: https://img.shields.io/npm/v/mongodb-data-service.svg?style=flat-square
156
142
  [npm_url]: https://www.npmjs.org/package/mongodb-data-service
157
- [scope-client]: https://github.com/mongodb-js/scope-client
158
143
  [driver]: https://github.com/mongodb/node-mongodb-native
159
144
  [dependabot_img]: https://api.dependabot.com/badges/status?host=github&repo=mongodb-js/data-service
160
145
  [dependabot_url]: https://app.dependabot.com/accounts/mongodb-js/repos/51536401
@@ -0,0 +1,11 @@
1
+ import { MongoClientOptions, MongoClient } from 'mongodb';
2
+ import SSHTunnel from '@mongodb-js/ssh-tunnel';
3
+ import { ConnectionOptions } from './connection-options';
4
+ export default function connectMongoClient(connectionOptions: ConnectionOptions, setupListeners: (client: MongoClient) => void, tunnelLocalPort: number): Promise<[
5
+ MongoClient,
6
+ SSHTunnel | undefined,
7
+ {
8
+ url: string;
9
+ options: MongoClientOptions;
10
+ }
11
+ ]>;
@@ -0,0 +1,88 @@
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 mongodb_1 = require("mongodb");
7
+ const mongodb_connection_string_url_1 = __importDefault(require("mongodb-connection-string-url"));
8
+ const resolve_mongodb_srv_1 = __importDefault(require("resolve-mongodb-srv"));
9
+ const redact_1 = require("./redact");
10
+ const compass_logging_1 = __importDefault(require("@mongodb-js/compass-logging"));
11
+ const ssh_tunnel_1 = require("./ssh-tunnel");
12
+ const { debug, log, mongoLogId } = compass_logging_1.default('COMPASS-CONNECT');
13
+ async function connectMongoClient(connectionOptions, setupListeners, tunnelLocalPort) {
14
+ var _a, _b;
15
+ debug('connectMongoClient invoked', redact_1.redactConnectionOptions(connectionOptions));
16
+ const [driverUrl, driverOptions] = connectionOptionsToMongoClientParams(connectionOptions);
17
+ const srvResolvedUrl = await resolveSrvRecord(driverUrl);
18
+ const [tunnel, urlWithSshTunnel] = await ssh_tunnel_1.openSshTunnel(srvResolvedUrl, connectionOptions.sshTunnel, tunnelLocalPort);
19
+ log.info(mongoLogId(1001000009), 'Connect', 'Initiating connection', {
20
+ url: redact_1.redactConnectionString(urlWithSshTunnel),
21
+ options: driverOptions,
22
+ });
23
+ const mongoClient = new mongodb_1.MongoClient(urlWithSshTunnel, driverOptions);
24
+ if (setupListeners) {
25
+ setupListeners(mongoClient);
26
+ }
27
+ try {
28
+ debug('waiting for MongoClient to connect ...');
29
+ await Promise.race([
30
+ (async () => {
31
+ await mongoClient.connect();
32
+ await mongoClient.db('admin').command({ ping: 1 });
33
+ })(),
34
+ ssh_tunnel_1.waitForTunnelError(tunnel),
35
+ ]);
36
+ log.info(mongoLogId(1001000012), 'Connect', 'Connection established', {
37
+ driver: (_b = (_a = mongoClient.options) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.driver,
38
+ url: redact_1.redactConnectionString(urlWithSshTunnel),
39
+ });
40
+ return [
41
+ mongoClient,
42
+ tunnel,
43
+ { url: urlWithSshTunnel, options: driverOptions },
44
+ ];
45
+ }
46
+ catch (err) {
47
+ log.error(mongoLogId(1001000013), 'Connect', 'Connection attempt failed', { error: err.message });
48
+ debug('connection error', err);
49
+ debug('force shutting down ssh tunnel ...');
50
+ await Promise.all([ssh_tunnel_1.forceCloseTunnel(tunnel), mongoClient.close()]).catch(() => {
51
+ });
52
+ throw err;
53
+ }
54
+ }
55
+ exports.default = connectMongoClient;
56
+ function connectionOptionsToMongoClientParams(connectionOptions) {
57
+ const url = new mongodb_connection_string_url_1.default(connectionOptions.connectionString);
58
+ const options = {
59
+ monitorCommands: true,
60
+ };
61
+ const isLoadBalanced = url.searchParams.get('loadBalanced') === 'true';
62
+ const isReplicaSet = url.isSRV || url.hosts.length > 1 || url.searchParams.has('replicaSet');
63
+ const hasDirectConnection = url.searchParams.has('directConnection');
64
+ if (!isReplicaSet && !isLoadBalanced && !hasDirectConnection) {
65
+ url.searchParams.set('directConnection', 'true');
66
+ }
67
+ if (!url.searchParams.has('tlsCertificateFile') &&
68
+ url.searchParams.has('tlsCertificateKeyFile')) {
69
+ url.searchParams.set('tlsCertificateFile', url.searchParams.get('tlsCertificateKeyFile'));
70
+ }
71
+ return [url.href, options];
72
+ }
73
+ async function resolveSrvRecord(url) {
74
+ let resolvedUrl;
75
+ try {
76
+ resolvedUrl = await resolve_mongodb_srv_1.default(url);
77
+ log.info(mongoLogId(1001000010), 'Connect', 'Resolved SRV record', {
78
+ from: redact_1.redactConnectionString(url),
79
+ to: redact_1.redactConnectionString(resolvedUrl),
80
+ });
81
+ }
82
+ catch (error) {
83
+ log.error(mongoLogId(1001000011), 'Connect', 'Resolving SRV record failed', { from: redact_1.redactConnectionString(url), error: error.message });
84
+ throw error;
85
+ }
86
+ return resolvedUrl;
87
+ }
88
+ //# sourceMappingURL=connect-mongo-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-mongo-client.js","sourceRoot":"","sources":["../src/connect-mongo-client.ts"],"names":[],"mappings":";;;;;AAAA,qCAA0D;AAE1D,kGAAgE;AAChE,8EAAoD;AACpD,qCAA2E;AAE3E,kFAAmE;AAEnE,6CAIsB;AAEtB,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,yBAAwB,CAAC,iBAAiB,CAAC,CAAC;AAEhE,KAAK,UAAU,kBAAkB,CAC9C,iBAAoC,EACpC,cAA6C,EAC7C,eAAuB;;IAQvB,KAAK,CACH,4BAA4B,EAC5B,gCAAuB,CAAC,iBAAiB,CAAC,CAC3C,CAAC;IAEF,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,GAC9B,oCAAoC,CAAC,iBAAiB,CAAC,CAAC;IAS1D,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAQzD,MAAM,CAAC,MAAM,EAAE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,CACxD,CAAC;KACH;IAED,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,GAAW;IACzC,IAAI,WAAmB,CAAC;IACxB,IAAI;QACF,WAAW,GAAG,MAAM,6BAAiB,CAAC,GAAG,CAAC,CAAC;QAC3C,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,UAAa,CAAC,EAAE,SAAS,EAAE,qBAAqB,EAAE;YACpE,IAAI,EAAE,+BAAsB,CAAC,GAAG,CAAC;YACjC,EAAE,EAAE,+BAAsB,CAAC,WAAW,CAAC;SACxC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAU,EAAE;QACnB,GAAG,CAAC,KAAK,CACP,UAAU,CAAC,UAAa,CAAC,EACzB,SAAS,EACT,6BAA6B,EAC7B,EAAE,IAAI,EAAE,+BAAsB,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAC5D,CAAC;QACF,MAAM,KAAK,CAAC;KACb;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
package/lib/connect.js CHANGED
@@ -3,23 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const util_1 = __importDefault(require("util"));
7
6
  const data_service_1 = __importDefault(require("./data-service"));
8
- const ConnectionModel = require('mongodb-connection-model');
9
- const connectionFromUri = util_1.default.promisify(ConnectionModel.from.bind(ConnectionModel));
10
7
  async function connect(connectionOptions) {
11
- const connectionModel = await connectionFromUri(connectionOptions.connectionString);
12
- if (!connectionOptions.sshTunnel) {
13
- connectionModel.sshTunnel = 'NONE';
14
- }
15
- else if (connectionOptions.sshTunnel.password) {
16
- connectionModel.sshTunnel = 'USER_PASSWORD';
17
- }
18
- else if (connectionOptions.sshTunnel.privateKeyFile) {
19
- connectionModel.sshTunnel = 'IDENTITY_FILE';
20
- }
21
- const dataService = new data_service_1.default(connectionModel);
22
- await util_1.default.promisify(dataService.connect.bind(dataService))();
8
+ const dataService = new data_service_1.default(connectionOptions);
9
+ await dataService.connect();
23
10
  return dataService;
24
11
  }
25
12
  exports.default = connect;
@@ -1 +1 @@
1
- {"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAGxB,kEAAyC;AAIzC,MAAM,eAAe,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAE5D,MAAM,iBAAiB,GAAG,cAAI,CAAC,SAAS,CACtC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAC3C,CAAC;AAEa,KAAK,UAAU,OAAO,CACnC,iBAAoC;IAEpC,MAAM,eAAe,GAA0B,MAAM,iBAAiB,CACpE,iBAAiB,CAAC,gBAAgB,CACnC,CAAC;IAEF,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE;QAChC,eAAe,CAAC,SAAS,GAAG,MAAM,CAAC;KACpC;SAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC/C,eAAe,CAAC,SAAS,GAAG,eAAe,CAAC;KAC7C;SAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,cAAc,EAAE;QACrD,eAAe,CAAC,SAAS,GAAG,eAAe,CAAC;KAC7C;IAED,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,eAAe,CAAC,CAAC;IAErD,MAAM,cAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;IAE9D,OAAO,WAAW,CAAC;AACrB,CAAC;AApBD,0BAoBC"}
1
+ {"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":";;;;;AACA,kEAAyC;AAE1B,KAAK,UAAU,OAAO,CACnC,iBAAoC;IAEpC,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,iBAAiB,CAAC,CAAC;IACvD,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAC5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAND,0BAMC"}
@@ -0,0 +1,12 @@
1
+ import { ConnectionOptions } from './connection-options';
2
+ export interface ConnectionInfo {
3
+ readonly id: string;
4
+ lastUsed?: Date;
5
+ favorite?: ConnectionFavoriteOptions;
6
+ connectionOptions: ConnectionOptions;
7
+ }
8
+ interface ConnectionFavoriteOptions {
9
+ name: string;
10
+ color?: string;
11
+ }
12
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=connection-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-info.js","sourceRoot":"","sources":["../src/connection-info.ts"],"names":[],"mappings":""}
@@ -1,20 +1,12 @@
1
1
  export interface ConnectionOptions {
2
- readonly id?: string;
3
- lastUsed?: Date;
4
2
  connectionString: string;
5
3
  sshTunnel?: ConnectionSshOptions;
6
- favorite?: ConnectionFavoriteOptions;
7
4
  }
8
5
  export interface ConnectionSshOptions {
9
6
  host: string;
10
7
  port: number;
11
8
  username: string;
12
9
  password?: string;
13
- privateKeyFile?: string;
14
- privateKeyPassphrase?: string;
10
+ identityKeyFile?: string;
11
+ identityKeyPassphrase?: string;
15
12
  }
16
- interface ConnectionFavoriteOptions {
17
- name: string;
18
- color?: string;
19
- }
20
- export {};
@@ -0,0 +1,13 @@
1
+ import { ConnectionInfo } from './connection-info';
2
+ export interface ConnectionSecrets {
3
+ password?: string;
4
+ sshTunnelPassphrase?: string;
5
+ awsSessionToken?: string;
6
+ tlsCertificateKeyFilePassword?: string;
7
+ proxyPassword?: string;
8
+ }
9
+ export declare function mergeSecrets(connectionInfo: Readonly<ConnectionInfo>, secrets: ConnectionSecrets | undefined): ConnectionInfo;
10
+ export declare function extractSecrets(connectionInfo: Readonly<ConnectionInfo>): {
11
+ connectionInfo: ConnectionInfo;
12
+ secrets: ConnectionSecrets;
13
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.extractSecrets = exports.mergeSecrets = void 0;
26
+ const lodash_1 = __importDefault(require("lodash"));
27
+ const mongodb_connection_string_url_1 = __importStar(require("mongodb-connection-string-url"));
28
+ function mergeSecrets(connectionInfo, secrets) {
29
+ const connectionInfoWithSecrets = lodash_1.default.cloneDeep(connectionInfo);
30
+ if (!secrets) {
31
+ return connectionInfoWithSecrets;
32
+ }
33
+ const connectionOptions = connectionInfoWithSecrets.connectionOptions;
34
+ const uri = new mongodb_connection_string_url_1.default(connectionOptions.connectionString);
35
+ if (secrets.password) {
36
+ uri.password = secrets.password;
37
+ }
38
+ if (secrets.sshTunnelPassphrase && connectionOptions.sshTunnel) {
39
+ connectionOptions.sshTunnel.identityKeyPassphrase =
40
+ secrets.sshTunnelPassphrase;
41
+ }
42
+ if (secrets.tlsCertificateKeyFilePassword) {
43
+ uri.searchParams.set('tlsCertificateKeyFilePassword', secrets.tlsCertificateKeyFilePassword);
44
+ }
45
+ if (secrets.proxyPassword) {
46
+ uri.searchParams.set('proxyPassword', secrets.proxyPassword);
47
+ }
48
+ if (secrets.awsSessionToken) {
49
+ const authMechanismProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(uri.searchParams.get('authMechanismProperties'));
50
+ authMechanismProperties.set('AWS_SESSION_TOKEN', secrets.awsSessionToken);
51
+ uri.searchParams.set('authMechanismProperties', authMechanismProperties.toString());
52
+ }
53
+ connectionInfoWithSecrets.connectionOptions.connectionString = uri.href;
54
+ return connectionInfoWithSecrets;
55
+ }
56
+ exports.mergeSecrets = mergeSecrets;
57
+ function extractSecrets(connectionInfo) {
58
+ var _a;
59
+ const connectionInfoWithoutSecrets = lodash_1.default.cloneDeep(connectionInfo);
60
+ const secrets = {};
61
+ const connectionOptions = connectionInfoWithoutSecrets.connectionOptions;
62
+ const uri = new mongodb_connection_string_url_1.default(connectionOptions.connectionString);
63
+ if (uri.password) {
64
+ secrets.password = uri.password;
65
+ uri.password = '';
66
+ }
67
+ if ((_a = connectionOptions.sshTunnel) === null || _a === void 0 ? void 0 : _a.identityKeyPassphrase) {
68
+ secrets.sshTunnelPassphrase =
69
+ connectionOptions.sshTunnel.identityKeyPassphrase;
70
+ delete connectionOptions.sshTunnel.identityKeyPassphrase;
71
+ }
72
+ if (uri.searchParams.has('tlsCertificateKeyFilePassword')) {
73
+ secrets.tlsCertificateKeyFilePassword =
74
+ uri.searchParams.get('tlsCertificateKeyFilePassword') || undefined;
75
+ uri.searchParams.delete('tlsCertificateKeyFilePassword');
76
+ }
77
+ if (uri.searchParams.has('proxyPassword')) {
78
+ secrets.proxyPassword = uri.searchParams.get('proxyPassword') || undefined;
79
+ uri.searchParams.delete('proxyPassword');
80
+ }
81
+ const authMechanismProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(uri.searchParams.get('authMechanismProperties'));
82
+ if (authMechanismProperties.has('AWS_SESSION_TOKEN')) {
83
+ secrets.awsSessionToken = authMechanismProperties.get('AWS_SESSION_TOKEN');
84
+ authMechanismProperties.delete('AWS_SESSION_TOKEN');
85
+ if (authMechanismProperties.toString()) {
86
+ uri.searchParams.set('authMechanismProperties', authMechanismProperties.toString());
87
+ }
88
+ else {
89
+ uri.searchParams.delete('authMechanismProperties');
90
+ }
91
+ }
92
+ connectionInfoWithoutSecrets.connectionOptions.connectionString = uri.href;
93
+ return { connectionInfo: connectionInfoWithoutSecrets, secrets };
94
+ }
95
+ exports.extractSecrets = extractSecrets;
96
+ //# sourceMappingURL=connection-secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-secrets.js","sourceRoot":"","sources":["../src/connection-secrets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,+FAEuC;AAWvC,SAAgB,YAAY,CAC1B,cAAwC,EACxC,OAAsC;IAEtC,MAAM,yBAAyB,GAAG,gBAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAE9D,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,yBAAyB,CAAC;KAClC;IAED,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,iBAAiB,CAAC;IAEtE,MAAM,GAAG,GAAG,IAAI,uCAAgB,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAErE,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;KACjC;IAED,IAAI,OAAO,CAAC,mBAAmB,IAAI,iBAAiB,CAAC,SAAS,EAAE;QAC9D,iBAAiB,CAAC,SAAS,CAAC,qBAAqB;YAC/C,OAAO,CAAC,mBAAmB,CAAC;KAC/B;IAED,IAAI,OAAO,CAAC,6BAA6B,EAAE;QACzC,GAAG,CAAC,YAAY,CAAC,GAAG,CAClB,+BAA+B,EAC/B,OAAO,CAAC,6BAA6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[]>;
4
+ save(connectionInfo: ConnectionInfo): Promise<void>;
5
+ delete(connectionOptions: ConnectionInfo): Promise<void>;
6
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionStorage = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const legacy_connection_model_1 = require("./legacy/legacy-connection-model");
6
+ class ConnectionStorage {
7
+ async loadAll() {
8
+ const { ConnectionCollection } = require('mongodb-connection-model');
9
+ const connectionCollection = new ConnectionCollection();
10
+ const fetchConnectionModels = promisifyAmpersandMethod(connectionCollection.fetch.bind(connectionCollection));
11
+ await fetchConnectionModels();
12
+ return connectionCollection.map(legacy_connection_model_1.convertConnectionModelToInfo);
13
+ }
14
+ async save(connectionInfo) {
15
+ if (!connectionInfo.id) {
16
+ throw new Error('id is required');
17
+ }
18
+ if (!uuid_1.validate(connectionInfo.id)) {
19
+ throw new Error('id must be a uuid');
20
+ }
21
+ const model = await legacy_connection_model_1.convertConnectionInfoToModel(connectionInfo);
22
+ model.save();
23
+ }
24
+ async delete(connectionOptions) {
25
+ if (!connectionOptions.id) {
26
+ return;
27
+ }
28
+ const model = await legacy_connection_model_1.convertConnectionInfoToModel(connectionOptions);
29
+ model.destroy();
30
+ }
31
+ }
32
+ exports.ConnectionStorage = ConnectionStorage;
33
+ function promisifyAmpersandMethod(fn) {
34
+ return () => new Promise((resolve, reject) => {
35
+ fn({
36
+ success: (model) => {
37
+ resolve(model);
38
+ },
39
+ error: (model, error) => {
40
+ reject(error);
41
+ },
42
+ });
43
+ });
44
+ }
45
+ //# sourceMappingURL=connection-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-storage.js","sourceRoot":"","sources":["../src/connection-storage.ts"],"names":[],"mappings":";;;AAEA,+BAAgD;AAChD,8EAI0C;AAE1C,MAAa,iBAAiB;IAM5B,KAAK,CAAC,OAAO;QAEX,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC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,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ConnectionInfo } from './connection-info';
2
+ export declare function getConnectionTitle(info: ConnectionInfo): string;
@@ -0,0 +1,25 @@
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
+ exports.getConnectionTitle = void 0;
7
+ const mongodb_connection_string_url_1 = __importDefault(require("mongodb-connection-string-url"));
8
+ function getConnectionTitle(info) {
9
+ var _a;
10
+ if ((_a = info.favorite) === null || _a === void 0 ? void 0 : _a.name) {
11
+ return info.favorite.name;
12
+ }
13
+ try {
14
+ const url = new mongodb_connection_string_url_1.default(info.connectionOptions.connectionString);
15
+ if (url.isSRV) {
16
+ return url.hosts[0];
17
+ }
18
+ return url.hosts.join(',');
19
+ }
20
+ catch (e) {
21
+ return info.connectionOptions.connectionString || 'Connection';
22
+ }
23
+ }
24
+ exports.getConnectionTitle = getConnectionTitle;
25
+ //# sourceMappingURL=connection-title.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-title.js","sourceRoot":"","sources":["../src/connection-title.ts"],"names":[],"mappings":";;;;;;AAAA,kGAA6D;AAG7D,SAAgB,kBAAkB,CAAC,IAAoB;;IACrD,IAAI,MAAA,IAAI,CAAC,QAAQ,0CAAE,IAAI,EAAE;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;KAC3B;IAED,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,uCAAgB,CAAC,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;QAC1E,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACrB;QAED,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC5B;IAAC,OAAO,CAAC,EAAE;QAEV,OAAO,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,IAAI,YAAY,CAAC;KAChE;AACH,CAAC;AAhBD,gDAgBC"}
@@ -1,22 +1,48 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { AggregateOptions, AggregationCursor, BulkWriteOptions, ClientSession, Collection, CollectionInfo, CountDocumentsOptions, CreateCollectionOptions, CreateIndexesOptions, DeleteOptions, DeleteResult, Document, EstimatedDocumentCountOptions, ExplainOptions, Filter, FindCursor, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexSpecification, InsertManyResult, InsertOneOptions, InsertOneResult, TopologyDescription, UpdateFilter, UpdateOptions, UpdateResult } from 'mongodb';
4
- import { NativeClient as NativeClientType, NativeClientConnectionOptions } from './native-client';
5
- import { Callback, Instance } from './types';
6
- import { LegacyConnectionModel } from './legacy-connection-model';
3
+ import { AggregateOptions, AggregationCursor, BulkWriteOptions, ClientSession, Collection, CountDocumentsOptions, CreateCollectionOptions, CreateIndexesOptions, DeleteOptions, DeleteResult, Document, EstimatedDocumentCountOptions, ExplainOptions, Filter, FindCursor, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexSpecification, InsertManyResult, InsertOneOptions, InsertOneResult, MongoClientOptions, ReadPreferenceLike, TopologyDescription, UpdateFilter, UpdateOptions, UpdateResult } from 'mongodb';
4
+ import ConnectionStringUrl from 'mongodb-connection-string-url';
5
+ import { ConnectionOptions } from './connection-options';
6
+ import { adaptCollectionInfo, adaptDatabaseInfo, InstanceDetails } from './instance-detail-helper';
7
+ import { Callback, CollectionStats } from './types';
8
+ import { ConnectionStatusWithPrivileges } from './run-command';
7
9
  declare class DataService extends EventEmitter {
8
- lastSeenTopology: TopologyDescription | null;
9
- client: NativeClientType;
10
- constructor(model: LegacyConnectionModel);
11
- getConnectionOptions(): NativeClientConnectionOptions | undefined;
10
+ private readonly _connectionOptions;
11
+ private _isConnecting;
12
+ private _mongoClientConnectionOptions?;
13
+ private _client?;
14
+ private _tunnel?;
15
+ private _lastSeenTopology;
16
+ private _isWritable;
17
+ private _isMongos;
18
+ private _id;
19
+ constructor(connectionOptions: ConnectionOptions);
20
+ getMongoClientConnectionOptions(): {
21
+ url: string;
22
+ options: MongoClientOptions;
23
+ } | undefined;
24
+ private _logCtx;
25
+ getConnectionOptions(): Readonly<ConnectionOptions>;
26
+ getConnectionString(): ConnectionStringUrl;
27
+ getReadPreference(): ReadPreferenceLike;
12
28
  collection(ns: string, options: unknown, callback: Callback<Document>): void;
13
- collectionStats(databaseName: string, collectionName: string, callback: Callback<Document>): void;
29
+ collections(databaseName: string, callback: Callback<CollectionStats[]>): void;
30
+ collectionStats(databaseName: string, collectionName: string, callback: Callback<CollectionStats>): void;
31
+ collectionInfo(dbName: string, collName: string): Promise<ReturnType<typeof adaptCollectionInfo> | null>;
14
32
  command(databaseName: string, comm: Document, callback: Callback<Document>): void;
15
33
  isWritable(): boolean;
16
34
  isMongos(): boolean;
17
- listCollections(databaseName: string, filter: Document, callback: Callback<CollectionInfo[]>): void;
18
- listDatabases(callback: Callback<Document>): void;
19
- connect(done: Callback<DataService>): void;
35
+ connectionStatus(): Promise<ConnectionStatusWithPrivileges>;
36
+ private _getPrivilegesOrFallback;
37
+ listCollections(databaseName: string, filter?: Document, { nameOnly, privileges, }?: {
38
+ nameOnly?: true;
39
+ privileges?: ConnectionStatusWithPrivileges['authInfo']['authenticatedUserPrivileges'] | null;
40
+ }): Promise<ReturnType<typeof adaptCollectionInfo>[]>;
41
+ listDatabases({ nameOnly, privileges, }?: {
42
+ nameOnly?: true;
43
+ privileges?: ConnectionStatusWithPrivileges['authInfo']['authenticatedUserPrivileges'] | null;
44
+ }): Promise<ReturnType<typeof adaptDatabaseInfo>[]>;
45
+ connect(): Promise<void>;
20
46
  estimatedCount(ns: string, options: EstimatedDocumentCountOptions, callback: Callback<number>): void;
21
47
  count(ns: string, filter: Filter<Document>, options: CountDocumentsOptions, callback: Callback<number>): void;
22
48
  createCollection(ns: string, options: CreateCollectionOptions, callback: Callback<Collection<Document>>): void;
@@ -24,7 +50,7 @@ declare class DataService extends EventEmitter {
24
50
  database(name: string, options: unknown, callback: Callback<Document>): void;
25
51
  deleteOne(ns: string, filter: Filter<Document>, options: DeleteOptions, callback: Callback<DeleteResult>): void;
26
52
  deleteMany(ns: string, filter: Filter<Document>, options: DeleteOptions, callback: Callback<DeleteResult>): void;
27
- disconnect(callback: Callback<never>): void;
53
+ disconnect(): Promise<void>;
28
54
  dropCollection(ns: string, callback: Callback<boolean>): void;
29
55
  dropDatabase(name: string, callback: Callback<boolean>): void;
30
56
  dropIndex(ns: string, name: string, callback: Callback<Document>): void;
@@ -37,11 +63,13 @@ declare class DataService extends EventEmitter {
37
63
  findOneAndUpdate(ns: string, filter: Filter<Document>, update: Document, options: FindOneAndUpdateOptions, callback: Callback<Document>): void;
38
64
  explain(ns: string, filter: Filter<Document>, options: ExplainOptions, callback: Callback<Document>): void;
39
65
  indexes(ns: string, options: unknown, callback: Callback<Document>): void;
40
- instance(options: unknown, callback: Callback<Instance>): void;
66
+ instance(): Promise<InstanceDetails>;
41
67
  insertOne(ns: string, doc: Document, options: InsertOneOptions, callback: Callback<InsertOneResult<Document>>): void;
42
68
  insertMany(ns: string, docs: Document[], options: BulkWriteOptions, callback: Callback<InsertManyResult<Document>>): void;
43
69
  putMany(ns: string, docs: Document[], options: BulkWriteOptions): Promise<InsertManyResult<Document>>;
44
- updateCollection(ns: string, flags: Document, callback: Callback<Document>): void;
70
+ updateCollection(ns: string, flags: Document & {
71
+ collMod?: never;
72
+ }, callback: Callback<Document>): void;
45
73
  updateOne(ns: string, filter: Filter<Document>, update: Document | UpdateFilter<Document>, options: UpdateOptions, callback: Callback<Document>): void;
46
74
  updateMany(ns: string, filter: Filter<Document>, update: UpdateFilter<Document>, options: UpdateOptions, callback: Callback<Document | UpdateResult>): void;
47
75
  currentOp(includeAll: boolean, callback: Callback<Document>): void;
@@ -51,13 +79,29 @@ declare class DataService extends EventEmitter {
51
79
  createView(name: string, sourceNs: string, pipeline: Document[], options: CreateCollectionOptions, callback: Callback<Collection<Document>>): void;
52
80
  updateView(name: string, sourceNs: string, pipeline: Document[], options: Document, callback: Callback<Document>): void;
53
81
  dropView(ns: string, callback: Callback<boolean>): void;
54
- sample(ns: string, args?: {
82
+ sample(ns: string, { query, size, fields, }?: {
55
83
  query?: Filter<Document>;
56
84
  size?: number;
57
85
  fields?: Document;
58
86
  }, options?: AggregateOptions): AggregationCursor;
59
87
  startSession(): ClientSession;
60
- killSession(session: ClientSession): Promise<Document>;
88
+ killSessions(sessions: ClientSession | ClientSession[]): Promise<Document>;
61
89
  isConnected(): boolean;
90
+ private setupListeners;
91
+ private get _initializedClient();
92
+ private get _defaultDb();
93
+ databaseStats(name: string): Promise<Omit<ReturnType<typeof adaptDatabaseInfo>, '_id'>>;
94
+ private _buildCollectionDetail;
95
+ private _buildCollectionStats;
96
+ private _buildDatabaseDetail;
97
+ _collection(ns: string): Collection;
98
+ private _collectionNames;
99
+ private _collectionName;
100
+ private _databaseName;
101
+ private _checkIsWritable;
102
+ private _checkIsMongos;
103
+ private _translateMessage;
104
+ private _cleanup;
105
+ private _startLogOp;
62
106
  }
63
- export = DataService;
107
+ export default DataService;