mongodb-data-service 21.12.0 → 21.15.1

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 (48) 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 +89 -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 -11
  11. package/lib/connection-secrets.d.ts +13 -0
  12. package/lib/connection-secrets.js +98 -0
  13. package/lib/connection-secrets.js.map +1 -0
  14. package/lib/connection-storage.d.ts +4 -6
  15. package/lib/connection-storage.js +8 -8
  16. package/lib/connection-storage.js.map +1 -1
  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 +40 -24
  21. package/lib/data-service.js +391 -172
  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 +77 -32
  27. package/lib/instance-detail-helper.js +143 -453
  28. package/lib/instance-detail-helper.js.map +1 -1
  29. package/lib/{legacy-connection-model.d.ts → legacy/legacy-connection-model.d.ts} +16 -7
  30. package/lib/legacy/legacy-connection-model.js +207 -0
  31. package/lib/legacy/legacy-connection-model.js.map +1 -0
  32. package/lib/redact.d.ts +5 -2
  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 +7 -99
  42. package/package.json +25 -26
  43. package/lib/.esm-wrapper.mjs +0 -3
  44. package/lib/legacy-connect.d.ts +0 -7
  45. package/lib/legacy-connect.js +0 -125
  46. package/lib/legacy-connect.js.map +0 -1
  47. package/lib/legacy-connection-model.js +0 -158
  48. package/lib/legacy-connection-model.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,89 @@
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 } = (0, compass_logging_1.default)('COMPASS-CONNECT');
13
+ async function connectMongoClient(connectionOptions, setupListeners, tunnelLocalPort) {
14
+ var _a, _b;
15
+ debug('connectMongoClient invoked', (0, redact_1.redactConnectionOptions)(connectionOptions));
16
+ const [driverUrl, driverOptions] = connectionOptionsToMongoClientParams(connectionOptions);
17
+ const srvResolvedUrl = await resolveSrvRecord(driverUrl);
18
+ const [tunnel, urlWithSshTunnel] = await (0, ssh_tunnel_1.openSshTunnel)(srvResolvedUrl, connectionOptions.sshTunnel, tunnelLocalPort);
19
+ log.info(mongoLogId(1001000009), 'Connect', 'Initiating connection', {
20
+ url: (0, 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
+ (0, 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: (0, 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([(0, 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 searchParams = url.typedSearchParams();
59
+ const options = {
60
+ monitorCommands: true,
61
+ };
62
+ const isLoadBalanced = searchParams.get('loadBalanced') === 'true';
63
+ const isReplicaSet = url.isSRV || url.hosts.length > 1 || searchParams.has('replicaSet');
64
+ const hasDirectConnection = searchParams.has('directConnection');
65
+ if (!isReplicaSet && !isLoadBalanced && !hasDirectConnection) {
66
+ searchParams.set('directConnection', 'true');
67
+ }
68
+ if (!searchParams.has('tlsCertificateFile') &&
69
+ searchParams.has('tlsCertificateKeyFile')) {
70
+ searchParams.set('tlsCertificateFile', searchParams.get('tlsCertificateKeyFile'));
71
+ }
72
+ return [url.href, options];
73
+ }
74
+ async function resolveSrvRecord(url) {
75
+ let resolvedUrl;
76
+ try {
77
+ resolvedUrl = await (0, resolve_mongodb_srv_1.default)(url);
78
+ log.info(mongoLogId(1001000010), 'Connect', 'Resolved SRV record', {
79
+ from: (0, redact_1.redactConnectionString)(url),
80
+ to: (0, redact_1.redactConnectionString)(resolvedUrl),
81
+ });
82
+ }
83
+ catch (error) {
84
+ log.error(mongoLogId(1001000011), 'Connect', 'Resolving SRV record failed', { from: (0, redact_1.redactConnectionString)(url), error: error.message });
85
+ throw error;
86
+ }
87
+ return resolvedUrl;
88
+ }
89
+ //# 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,IAAA,yBAAwB,EAAC,iBAAiB,CAAC,CAAC;AAEhE,KAAK,UAAU,kBAAkB,CAC9C,iBAAoC,EACpC,cAA6C,EAC7C,eAAuB;;IAQvB,KAAK,CACH,4BAA4B,EAC5B,IAAA,gCAAuB,EAAC,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,gB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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,IAAA,6BAAiB,EAAC,GAAG,CAAC,CAAC;QAC3C,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,UAAa,CAAC,EAAE,SAAS,EAAE,qBAAqB,EAAE;YACpE,IAAI,EAAE,IAAA,+BAAsB,EAAC,GAAG,CAAC;YACjC,EAAE,EAAE,IAAA,+BAAsB,EAAC,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,IAAA,+BAAsB,EAAC,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,21 +1,12 @@
1
1
  export interface ConnectionOptions {
2
- readonly id?: string;
3
- lastUsed?: Date;
4
2
  connectionString: string;
5
- tlsCertificateFile?: string;
6
3
  sshTunnel?: ConnectionSshOptions;
7
- favorite?: ConnectionFavoriteOptions;
8
4
  }
9
5
  export interface ConnectionSshOptions {
10
6
  host: string;
11
7
  port: number;
12
8
  username: string;
13
9
  password?: string;
14
- privateKeyFile?: string;
15
- privateKeyPassphrase?: string;
10
+ identityKeyFile?: string;
11
+ identityKeyPassphrase?: string;
16
12
  }
17
- interface ConnectionFavoriteOptions {
18
- name: string;
19
- color?: string;
20
- }
21
- 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,98 @@
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
+ const searchParams = uri.typedSearchParams();
36
+ if (secrets.password) {
37
+ uri.password = secrets.password;
38
+ }
39
+ if (secrets.sshTunnelPassphrase && connectionOptions.sshTunnel) {
40
+ connectionOptions.sshTunnel.identityKeyPassphrase =
41
+ secrets.sshTunnelPassphrase;
42
+ }
43
+ if (secrets.tlsCertificateKeyFilePassword) {
44
+ searchParams.set('tlsCertificateKeyFilePassword', secrets.tlsCertificateKeyFilePassword);
45
+ }
46
+ if (secrets.proxyPassword) {
47
+ searchParams.set('proxyPassword', secrets.proxyPassword);
48
+ }
49
+ if (secrets.awsSessionToken) {
50
+ const authMechanismProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(searchParams.get('authMechanismProperties'));
51
+ authMechanismProperties.set('AWS_SESSION_TOKEN', secrets.awsSessionToken);
52
+ searchParams.set('authMechanismProperties', authMechanismProperties.toString());
53
+ }
54
+ connectionInfoWithSecrets.connectionOptions.connectionString = uri.href;
55
+ return connectionInfoWithSecrets;
56
+ }
57
+ exports.mergeSecrets = mergeSecrets;
58
+ function extractSecrets(connectionInfo) {
59
+ var _a;
60
+ const connectionInfoWithoutSecrets = lodash_1.default.cloneDeep(connectionInfo);
61
+ const secrets = {};
62
+ const connectionOptions = connectionInfoWithoutSecrets.connectionOptions;
63
+ const uri = new mongodb_connection_string_url_1.default(connectionOptions.connectionString);
64
+ const searchParams = uri.typedSearchParams();
65
+ if (uri.password) {
66
+ secrets.password = uri.password;
67
+ uri.password = '';
68
+ }
69
+ if ((_a = connectionOptions.sshTunnel) === null || _a === void 0 ? void 0 : _a.identityKeyPassphrase) {
70
+ secrets.sshTunnelPassphrase =
71
+ connectionOptions.sshTunnel.identityKeyPassphrase;
72
+ delete connectionOptions.sshTunnel.identityKeyPassphrase;
73
+ }
74
+ if (searchParams.has('tlsCertificateKeyFilePassword')) {
75
+ secrets.tlsCertificateKeyFilePassword =
76
+ searchParams.get('tlsCertificateKeyFilePassword') || undefined;
77
+ searchParams.delete('tlsCertificateKeyFilePassword');
78
+ }
79
+ if (searchParams.has('proxyPassword')) {
80
+ secrets.proxyPassword = searchParams.get('proxyPassword') || undefined;
81
+ searchParams.delete('proxyPassword');
82
+ }
83
+ const authMechanismProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(searchParams.get('authMechanismProperties'));
84
+ if (authMechanismProperties.has('AWS_SESSION_TOKEN')) {
85
+ secrets.awsSessionToken = authMechanismProperties.get('AWS_SESSION_TOKEN');
86
+ authMechanismProperties.delete('AWS_SESSION_TOKEN');
87
+ if (authMechanismProperties.toString()) {
88
+ searchParams.set('authMechanismProperties', authMechanismProperties.toString());
89
+ }
90
+ else {
91
+ searchParams.delete('authMechanismProperties');
92
+ }
93
+ }
94
+ connectionInfoWithoutSecrets.connectionOptions.connectionString = uri.href;
95
+ return { connectionInfo: connectionInfoWithoutSecrets, secrets };
96
+ }
97
+ exports.extractSecrets = extractSecrets;
98
+ //# 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;AAYvC,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,MAAM,YAAY,GAAG,GAAG,CAAC,iBAAiB,EAEvC,CAAC;IAEJ,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,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SAAS,CAAC,qBAAqB,CAAC;QACpD,OAAO,iBAAiB,CAAC,SAAS,CAAC,qBAAqB,CAAC;KAC1D;IAED,IAAI,YAAY,CAAC,GAAG,CAAC,+BAA+B,CAAC,EAAE;QACrD,OAAO,CAAC,6BAA6B;YACnC,YAAY,CAAC,GAAG,CAAC,+BAA+B,CAAC,IAAI,SAAS,CAAC;QACjE,YAAY,CAAC,MAAM,CAAC,+BAA+B,CAAC,CAAC;KACtD;IAED,IAAI,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;QACrC,OAAO,CAAC,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,SAAS,CAAC;QACvE,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;KACtC;IAED,MAAM,uBAAuB,GAC3B,IAAI,4DAA4B,CAC9B,YAAY,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAC5C,CAAC;IAEJ,IAAI,uBAAuB,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE;QACpD,OAAO,CAAC,eAAe,GAAG,uBAAuB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC3E,uBAAuB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAEpD,IAAI,uBAAuB,CAAC,QAAQ,EAAE,EAAE;YACtC,YAAY,CAAC,GAAG,CACd,yBAAyB,EACzB,uBAAuB,CAAC,QAAQ,EAAE,CACnC,CAAC;SACH;aAAM;YACL,YAAY,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;SAChD;KACF;IAED,4BAA4B,CAAC,iBAAiB,CAAC,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAC;IAE3E,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAE,OAAO,EAAE,CAAC;AACnE,CAAC;AA1DD,wCA0DC"}
@@ -1,8 +1,6 @@
1
- import { ConnectionOptions } from './connection-options';
2
- declare type ConnectionOptionsWithRequiredId = ConnectionOptions & Required<Pick<ConnectionOptions, 'id'>>;
1
+ import { ConnectionInfo } from './connection-info';
3
2
  export declare class ConnectionStorage {
4
- loadAll(): Promise<ConnectionOptions[]>;
5
- save(connectionOptions: ConnectionOptionsWithRequiredId): Promise<void>;
6
- delete(connectionOptions: ConnectionOptionsWithRequiredId): Promise<void>;
3
+ loadAll(): Promise<ConnectionInfo[]>;
4
+ save(connectionInfo: ConnectionInfo): Promise<void>;
5
+ delete(connectionOptions: ConnectionInfo): Promise<void>;
7
6
  }
8
- export {};
@@ -1,31 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionStorage = void 0;
4
- const { ConnectionCollection } = require('mongodb-connection-model');
5
- const legacy_connection_model_1 = require("./legacy-connection-model");
6
4
  const uuid_1 = require("uuid");
5
+ const legacy_connection_model_1 = require("./legacy/legacy-connection-model");
7
6
  class ConnectionStorage {
8
7
  async loadAll() {
8
+ const { ConnectionCollection } = require('mongodb-connection-model');
9
9
  const connectionCollection = new ConnectionCollection();
10
10
  const fetchConnectionModels = promisifyAmpersandMethod(connectionCollection.fetch.bind(connectionCollection));
11
11
  await fetchConnectionModels();
12
- return connectionCollection.map(legacy_connection_model_1.convertConnectionModelToOptions);
12
+ return connectionCollection.map(legacy_connection_model_1.convertConnectionModelToInfo);
13
13
  }
14
- async save(connectionOptions) {
15
- if (!connectionOptions.id) {
14
+ async save(connectionInfo) {
15
+ if (!connectionInfo.id) {
16
16
  throw new Error('id is required');
17
17
  }
18
- if (!uuid_1.validate(connectionOptions.id)) {
18
+ if (!(0, uuid_1.validate)(connectionInfo.id)) {
19
19
  throw new Error('id must be a uuid');
20
20
  }
21
- const model = await legacy_connection_model_1.convertConnectionOptionsToModel(connectionOptions);
21
+ const model = await (0, legacy_connection_model_1.convertConnectionInfoToModel)(connectionInfo);
22
22
  model.save();
23
23
  }
24
24
  async delete(connectionOptions) {
25
25
  if (!connectionOptions.id) {
26
26
  return;
27
27
  }
28
- const model = await legacy_connection_model_1.convertConnectionOptionsToModel(connectionOptions);
28
+ const model = await (0, legacy_connection_model_1.convertConnectionInfoToModel)(connectionOptions);
29
29
  model.destroy();
30
30
  }
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connection-storage.js","sourceRoot":"","sources":["../src/connection-storage.ts"],"names":[],"mappings":";;;AAGA,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAErE,uEAImC;AAKnC,+BAAgD;AAEhD,MAAa,iBAAiB;IAM5B,KAAK,CAAC,OAAO;QACX,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACxD,MAAM,qBAAqB,GAAG,wBAAwB,CACpD,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CACtD,CAAC;QAEF,MAAM,qBAAqB,EAAE,CAAC;QAC9B,OAAO,oBAAoB,CAAC,GAAG,CAAC,yDAA+B,CAAC,CAAC;IACnE,CAAC;IAUD,KAAK,CAAC,IAAI,CACR,iBAAkD;QAElD,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;SACnC;QAED,IAAI,CAAC,eAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QAED,MAAM,KAAK,GAAG,MAAM,yDAA+B,CAAC,iBAAiB,CAAC,CAAC;QACvE,KAAK,CAAC,IAAI,EAAE,CAAC;IACf,CAAC;IAaD,KAAK,CAAC,MAAM,CACV,iBAAkD;QAElD,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE;YAGzB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,MAAM,yDAA+B,CAAC,iBAAiB,CAAC,CAAC;QACvE,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF;AA9DD,8CA8DC;AAED,SAAS,wBAAwB,C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CAAC,MAAM,CAAC,iBAAiC;QAC5C,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE;YAGzB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,MAAM,IAAA,sDAA4B,EAAC,iBAAiB,CAAC,CAAC;QACpE,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF;AA5DD,8CA4DC;AAED,SAAS,wBAAwB,CAC/B,EAAgD;IAEhD,OAAO,GAAG,EAAE,CACV,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9B,EAAE,CAAC;YACD,OAAO,EAAE,CAAC,KAAQ,EAAE,EAAE;gBACpB,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YACD,KAAK,EAAE,CAAC,KAAQ,EAAE,KAAY,EAAE,EAAE;gBAChC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;SACF,CAAC,CAAC;IACL,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,37 +1,51 @@
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, MongoClientOptions, TopologyDescription, UpdateFilter, UpdateOptions, UpdateResult } from 'mongodb';
4
- import { LegacyConnectionModel } from './legacy-connection-model';
5
- import { Callback, CollectionStats, Instance } from './types';
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';
6
9
  declare class DataService extends EventEmitter {
7
- lastSeenTopology: TopologyDescription | null;
8
- model: LegacyConnectionModel;
10
+ private readonly _connectionOptions;
9
11
  private _isConnecting;
10
12
  private _mongoClientConnectionOptions?;
11
13
  private _client?;
12
- private _database?;
13
- private _tunnel;
14
+ private _tunnel?;
15
+ private _lastSeenTopology;
14
16
  private _isWritable;
15
17
  private _isMongos;
16
18
  private _id;
17
- constructor(model: LegacyConnectionModel);
19
+ constructor(connectionOptions: ConnectionOptions);
18
20
  getMongoClientConnectionOptions(): {
19
21
  url: string;
20
22
  options: MongoClientOptions;
21
23
  } | undefined;
22
24
  private _logCtx;
25
+ getConnectionOptions(): Readonly<ConnectionOptions>;
26
+ getConnectionString(): ConnectionStringUrl;
27
+ getReadPreference(): ReadPreferenceLike;
23
28
  collection(ns: string, options: unknown, callback: Callback<Document>): void;
24
29
  collections(databaseName: string, callback: Callback<CollectionStats[]>): void;
25
30
  collectionStats(databaseName: string, collectionName: string, callback: Callback<CollectionStats>): void;
31
+ collectionInfo(dbName: string, collName: string): Promise<ReturnType<typeof adaptCollectionInfo> | null>;
26
32
  command(databaseName: string, comm: Document, callback: Callback<Document>): void;
27
33
  isWritable(): boolean;
28
34
  isMongos(): boolean;
29
- listCollections(databaseName: string, filter: Document, options: {
30
- nameOnly: boolean;
31
- }, callback: Callback<CollectionInfo[]>): void;
32
- listCollections(databaseName: string, filter: Document, callback: Callback<CollectionInfo[]>): void;
33
- listDatabases(callback: Callback<Document>): void;
34
- 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<{
45
+ _id: string;
46
+ name: string;
47
+ }[]>;
48
+ connect(): Promise<void>;
35
49
  estimatedCount(ns: string, options: EstimatedDocumentCountOptions, callback: Callback<number>): void;
36
50
  count(ns: string, filter: Filter<Document>, options: CountDocumentsOptions, callback: Callback<number>): void;
37
51
  createCollection(ns: string, options: CreateCollectionOptions, callback: Callback<Collection<Document>>): void;
@@ -39,7 +53,7 @@ declare class DataService extends EventEmitter {
39
53
  database(name: string, options: unknown, callback: Callback<Document>): void;
40
54
  deleteOne(ns: string, filter: Filter<Document>, options: DeleteOptions, callback: Callback<DeleteResult>): void;
41
55
  deleteMany(ns: string, filter: Filter<Document>, options: DeleteOptions, callback: Callback<DeleteResult>): void;
42
- disconnect(callback: Callback<never>): void;
56
+ disconnect(): Promise<void>;
43
57
  dropCollection(ns: string, callback: Callback<boolean>): void;
44
58
  dropDatabase(name: string, callback: Callback<boolean>): void;
45
59
  dropIndex(ns: string, name: string, callback: Callback<Document>): void;
@@ -52,7 +66,7 @@ declare class DataService extends EventEmitter {
52
66
  findOneAndUpdate(ns: string, filter: Filter<Document>, update: Document, options: FindOneAndUpdateOptions, callback: Callback<Document>): void;
53
67
  explain(ns: string, filter: Filter<Document>, options: ExplainOptions, callback: Callback<Document>): void;
54
68
  indexes(ns: string, options: unknown, callback: Callback<Document>): void;
55
- instance(options: unknown, callback: Callback<Instance>): void;
69
+ instance(): Promise<InstanceDetails>;
56
70
  insertOne(ns: string, doc: Document, options: InsertOneOptions, callback: Callback<InsertOneResult<Document>>): void;
57
71
  insertMany(ns: string, docs: Document[], options: BulkWriteOptions, callback: Callback<InsertManyResult<Document>>): void;
58
72
  putMany(ns: string, docs: Document[], options: BulkWriteOptions): Promise<InsertManyResult<Document>>;
@@ -74,23 +88,25 @@ declare class DataService extends EventEmitter {
74
88
  fields?: Document;
75
89
  }, options?: AggregateOptions): AggregationCursor;
76
90
  startSession(): ClientSession;
77
- killSession(session: ClientSession): Promise<Document>;
91
+ killSessions(sessions: ClientSession | ClientSession[]): Promise<Document>;
78
92
  isConnected(): boolean;
79
93
  private setupListeners;
80
- private get mongoClient();
81
- private get db();
82
- private databaseStats;
94
+ private get _initializedClient();
95
+ private get _defaultDb();
96
+ databaseStats(name: string): Promise<ReturnType<typeof adaptDatabaseInfo> & {
97
+ name: string;
98
+ }>;
83
99
  private _buildCollectionDetail;
84
100
  private _buildCollectionStats;
85
101
  private _buildDatabaseDetail;
86
- private _buildDatabaseStats;
87
102
  _collection(ns: string): Collection;
88
103
  private _collectionNames;
89
104
  private _collectionName;
90
105
  private _databaseName;
91
- private checkIsWritable;
92
- private checkIsMongos;
106
+ private _checkIsWritable;
107
+ private _checkIsMongos;
93
108
  private _translateMessage;
94
109
  private _cleanup;
110
+ private _startLogOp;
95
111
  }
96
- export = DataService;
112
+ export default DataService;