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
@@ -3,486 +3,176 @@ 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
- exports.listDatabases = exports.listCollections = exports.getInstance = exports.getHostInfo = exports.getDataLake = exports.getGenuineMongoDB = exports.getDatabaseCollections = exports.getCmdLineOpts = exports.getBuildInfo = exports.getAllowedDatabases = exports.getAllowedCollections = void 0;
7
- const async_1 = __importDefault(require("async"));
8
- const debug_1 = __importDefault(require("debug"));
9
- const lodash_1 = require("lodash");
10
- const mongodb_1 = require("mongodb");
11
- const isNotAuthorized = require('mongodb-js-errors').isNotAuthorized;
12
- const toNS = require('mongodb-ns');
13
- const security = require('mongodb-security');
14
- const getMongoDBBuildInfo = require('mongodb-build-info');
15
- const debug = debug_1.default('mongodb-data-service:instance-detail-helper');
16
- function getReadPreferenceOptions(db) {
17
- const readPreference = db.readPreference
18
- ? db.readPreference
19
- : mongodb_1.ReadPreference.PRIMARY;
20
- return { readPreference };
21
- }
22
- function getStats(results, done) {
23
- const databases = results.databases;
24
- const keys = [
25
- 'document_count',
26
- 'storage_size',
27
- 'index_count',
28
- 'index_size',
29
- ];
30
- const stats = {
31
- document_count: 0,
32
- storage_size: 0,
33
- index_count: 0,
34
- index_size: 0,
35
- };
36
- databases.map(function (db) {
37
- keys.map(function (k) {
38
- stats[k] += db[k];
39
- });
40
- });
41
- done(null, stats);
42
- }
43
- function parseBuildInfo(buildInfo) {
44
- buildInfo = buildInfo || {};
6
+ exports.adaptCollectionInfo = exports.adaptDatabaseInfo = exports.getPrivilegesByDatabaseAndCollection = exports.getInstance = void 0;
7
+ const mongodb_build_info_1 = require("mongodb-build-info");
8
+ const mongodb_ns_1 = __importDefault(require("mongodb-ns"));
9
+ const compass_logging_1 = __importDefault(require("@mongodb-js/compass-logging"));
10
+ const run_command_1 = require("./run-command");
11
+ const { debug } = (0, compass_logging_1.default)('COMPASS-CONNECT');
12
+ async function getInstance(client) {
13
+ var _a;
14
+ const adminDb = client.db('admin');
15
+ const [connectionStatus, getCmdLineOptsResult, hostInfoResult, buildInfoResult, getParameterResult, atlasVersionResult,] = await Promise.all([
16
+ (0, run_command_1.runCommand)(adminDb, { connectionStatus: 1, showPrivileges: true }).catch(ignoreNotAuthorized(null)),
17
+ (0, run_command_1.runCommand)(adminDb, { getCmdLineOpts: 1 }).catch((err) => {
18
+ return { errmsg: err.message };
19
+ }),
20
+ (0, run_command_1.runCommand)(adminDb, { hostInfo: 1 }).catch(ignoreNotAuthorized({})),
21
+ (0, run_command_1.runCommand)(adminDb, { buildInfo: 1 }),
22
+ (0, run_command_1.runCommand)(adminDb, {
23
+ getParameter: 1,
24
+ featureCompatibilityVersion: 1,
25
+ }).catch(() => null),
26
+ (0, run_command_1.runCommand)(adminDb, { atlasVersion: 1 }).catch((err) => {
27
+ return { version: '', gitVersion: '' };
28
+ }),
29
+ ]);
45
30
  return {
46
- version: buildInfo.version,
47
- commit: buildInfo.gitVersion,
48
- commit_url: buildInfo.gitVersion
49
- ? `https://github.com/mongodb/mongo/commit/${buildInfo.gitVersion}`
50
- : '',
51
- flags_loader: buildInfo.loaderFlags,
52
- flags_compiler: buildInfo.compilerFlags,
53
- allocator: buildInfo.allocator,
54
- javascript_engine: buildInfo.javascriptEngine,
55
- debug: buildInfo.debug,
56
- for_bits: buildInfo.bits,
57
- max_bson_object_size: buildInfo.maxBsonObjectSize,
58
- enterprise_module: getMongoDBBuildInfo.isEnterprise(buildInfo),
59
- query_engine: buildInfo.queryEngine ? buildInfo.queryEngine : null,
60
- raw: buildInfo,
61
- };
62
- }
63
- function getBuildInfo(results, done) {
64
- const db = results.db;
65
- debug('checking we can get buildInfo...');
66
- const spec = {
67
- buildInfo: 1,
68
- };
69
- const adminDb = db.databaseName === 'admin' ? db : db.admin();
70
- void adminDb.command(spec, getReadPreferenceOptions(db), (err, res) => {
71
- if (err) {
72
- debug('buildInfo failed!', err);
73
- err.command = 'buildInfo';
74
- return done(err);
75
- }
76
- done(null, parseBuildInfo(res));
77
- });
78
- }
79
- exports.getBuildInfo = getBuildInfo;
80
- function getFeatureCompatibilityVersion(results, done) {
81
- const db = results.db;
82
- const spec = {
83
- getParameter: 1,
84
- featureCompatibilityVersion: 1,
31
+ auth: adaptAuthInfo(connectionStatus),
32
+ build: adaptBuildInfo(buildInfoResult),
33
+ host: adaptHostInfo(hostInfoResult),
34
+ genuineMongoDB: buildGenuineMongoDBInfo(buildInfoResult, getCmdLineOptsResult),
35
+ dataLake: buildDataLakeInfo(buildInfoResult),
36
+ featureCompatibilityVersion: (_a = getParameterResult === null || getParameterResult === void 0 ? void 0 : getParameterResult.featureCompatibilityVersion.version) !== null && _a !== void 0 ? _a : null,
37
+ isAtlas: checkIsAtlas(client, atlasVersionResult),
85
38
  };
86
- const adminDb = db.databaseName === 'admin' ? db : db.admin();
87
- void adminDb.command(spec, getReadPreferenceOptions(db), (err, res) => {
88
- var _a, _b;
89
- if (err) {
90
- return done(null, null);
91
- }
92
- done(null, (_b = (_a = res === null || res === void 0 ? void 0 : res.featureCompatibilityVersion) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : null);
93
- });
94
39
  }
95
- function getCmdLineOpts(results, done) {
96
- const db = results.db;
97
- const spec = {
98
- getCmdLineOpts: 1,
99
- };
100
- const adminDb = db.databaseName === 'admin' ? db : db.admin();
101
- void adminDb.command(spec, getReadPreferenceOptions(db), (err, res) => {
102
- if (err) {
103
- debug('getCmdLineOpts failed!', err);
104
- return done(null, { errmsg: err.message });
105
- }
106
- done(null, res);
107
- });
40
+ exports.getInstance = getInstance;
41
+ function checkIsAtlas(client, atlasVersionInfo) {
42
+ var _a;
43
+ const firstHost = ((_a = client.options.hosts[0]) === null || _a === void 0 ? void 0 : _a.host) || '';
44
+ if (atlasVersionInfo.version === '') {
45
+ return /mongodb(-dev)?\.net$/i.test(firstHost);
46
+ }
47
+ return true;
108
48
  }
109
- exports.getCmdLineOpts = getCmdLineOpts;
110
- function getGenuineMongoDB(results, done) {
111
- const buildInfo = results.build.raw;
112
- const cmdLineOpts = results.cmdLineOpts;
113
- debug('genuineMongoDB check: buildInfo and cmdLineOpts', buildInfo, cmdLineOpts);
114
- const { isGenuine, serverName } = getMongoDBBuildInfo.getGenuineMongoDB(buildInfo, cmdLineOpts);
115
- done(null, {
49
+ function buildGenuineMongoDBInfo(buildInfo, cmdLineOpts) {
50
+ const { isGenuine, serverName } = (0, mongodb_build_info_1.getGenuineMongoDB)(buildInfo, cmdLineOpts);
51
+ return {
116
52
  isGenuine,
117
53
  dbType: serverName,
118
- });
54
+ };
119
55
  }
120
- exports.getGenuineMongoDB = getGenuineMongoDB;
121
- function getDataLake(results, done) {
122
- const buildInfo = results.build.raw;
123
- debug('isDataLake check: buildInfo.dataLake', buildInfo.dataLake);
124
- const { isDataLake, dlVersion } = getMongoDBBuildInfo.getDataLake(buildInfo);
125
- done(null, {
56
+ function buildDataLakeInfo(buildInfo) {
57
+ const { isDataLake, dlVersion } = (0, mongodb_build_info_1.getDataLake)(buildInfo);
58
+ return {
126
59
  isDataLake,
127
60
  version: dlVersion,
128
- });
61
+ };
129
62
  }
130
- exports.getDataLake = getDataLake;
131
- function parseHostInfo(hostInfo) {
132
- hostInfo = hostInfo || {};
133
- const hostInfoSystem = hostInfo.system || {};
134
- const hostInfoOs = hostInfo.os || {};
135
- const hostInfoExtra = hostInfo.extra || {};
63
+ function adaptAuthInfo(connectionStatus) {
64
+ var _a;
65
+ if (connectionStatus === null) {
66
+ return { user: null, roles: [], privileges: [] };
67
+ }
68
+ const { authenticatedUsers, authenticatedUserRoles, authenticatedUserPrivileges, } = connectionStatus.authInfo;
136
69
  return {
137
- system_time: hostInfoSystem.currentTime,
138
- hostname: hostInfoSystem.hostname || 'unknown',
139
- os: hostInfoOs.name,
140
- os_family: (hostInfoOs.type || 'unknown').toLowerCase(),
141
- kernel_version: hostInfoOs.version,
142
- kernel_version_string: hostInfoExtra.versionString,
143
- memory_bits: (hostInfoSystem.memSizeMB || 0) * 1024 * 1024,
144
- memory_page_size: hostInfoExtra.pageSize,
145
- arch: hostInfoSystem.cpuArch,
146
- cpu_cores: hostInfoSystem.numCores,
147
- cpu_cores_physical: hostInfoExtra.physicalCores,
148
- cpu_scheduler: hostInfoExtra.scheduler,
149
- cpu_frequency: (hostInfoExtra.cpuFrequencyMHz || 0) * 1000000,
150
- cpu_string: hostInfoExtra.cpuString,
151
- cpu_bits: hostInfoSystem.cpuAddrSize,
152
- machine_model: hostInfoExtra.model,
153
- feature_numa: hostInfoSystem.numaEnabled,
154
- feature_always_full_sync: hostInfoExtra.alwaysFullSync,
155
- feature_nfs_async: hostInfoExtra.nfsAsync,
70
+ user: (_a = authenticatedUsers[0]) !== null && _a !== void 0 ? _a : null,
71
+ roles: authenticatedUserRoles,
72
+ privileges: authenticatedUserPrivileges,
156
73
  };
157
74
  }
158
- function getHostInfo(results, done) {
159
- const db = results.db;
160
- const spec = {
161
- hostInfo: 1,
162
- };
163
- const adminDb = db.databaseName === 'admin' ? db : db.admin();
164
- void adminDb.command(spec, getReadPreferenceOptions(db), (err, res) => {
165
- if (err) {
166
- if (isNotAuthorized(err)) {
167
- debug('user does not have hostInfo privilege, returning empty document {}');
168
- done(null, {});
169
- return;
75
+ function getPrivilegesByDatabaseAndCollection(authenticatedUserPrivileges = null, requiredActions = null) {
76
+ const privileges = authenticatedUserPrivileges !== null && authenticatedUserPrivileges !== void 0 ? authenticatedUserPrivileges : [];
77
+ const filteredPrivileges = requiredActions && requiredActions.length > 0
78
+ ? privileges.filter(({ actions }) => {
79
+ return requiredActions.every((action) => actions.includes(action));
80
+ })
81
+ : privileges;
82
+ const result = {};
83
+ for (const { resource, actions } of filteredPrivileges) {
84
+ if (typeof resource.db !== 'undefined' &&
85
+ typeof resource.collection !== 'undefined') {
86
+ const { db, collection } = resource;
87
+ if (result[db]) {
88
+ Object.assign(result[db], { [collection]: actions });
170
89
  }
171
- debug('driver error', err);
172
- err.command = 'hostInfo';
173
- done(err);
174
- return;
175
- }
176
- done(null, parseHostInfo(res));
177
- });
178
- }
179
- exports.getHostInfo = getHostInfo;
180
- function listDatabases(results, done) {
181
- const db = results.db;
182
- const userInfo = results.userInfo;
183
- const cluster = security
184
- .getResourcesWithActions(userInfo, ['listDatabases'])
185
- .filter(function (resource) {
186
- return resource.cluster;
187
- });
188
- if (!cluster) {
189
- done(null, []);
190
- }
191
- const spec = {
192
- listDatabases: 1,
193
- };
194
- const options = getReadPreferenceOptions(db);
195
- const adminDb = db.databaseName === 'admin' ? db : db.admin();
196
- void adminDb.command(spec, options, function (err, res) {
197
- if (err) {
198
- if (isNotAuthorized(err)) {
199
- void adminDb.command({ connectionStatus: 1, showPrivileges: 1 }, options, function (err, res) {
200
- if (err) {
201
- done(err);
202
- return;
203
- }
204
- const privileges = (res.authInfo || {})
205
- .authenticatedUserPrivileges;
206
- if (privileges === undefined) {
207
- done(null, []);
208
- return;
209
- }
210
- done(null, privileges
211
- .filter(function (priv) {
212
- return ((priv.resource || {}).db || '').length > 0;
213
- })
214
- .map(function (priv) {
215
- return priv.resource.db;
216
- })
217
- .filter(function (db, idx, arr) {
218
- return arr.indexOf(db) === idx;
219
- })
220
- .sort());
221
- });
222
- return;
90
+ else {
91
+ result[db] = { [collection]: actions };
223
92
  }
224
- debug('listDatabases failed', err);
225
- err.command = 'listDatabases';
226
- done(err);
227
- return;
228
93
  }
229
- const names = res.databases.map(function (d) {
230
- return d.name;
231
- });
232
- debug('listDatabases succeeded!', {
233
- res: JSON.stringify(res),
234
- names: names,
235
- });
236
- done(null, names);
237
- });
238
- }
239
- exports.listDatabases = listDatabases;
240
- function getDatabase(client, db, name, done) {
241
- if (typeof name === 'function') {
242
- done = name;
243
- name = db.databaseName;
244
94
  }
245
- const spec = {
246
- dbStats: 1,
247
- };
248
- const options = getReadPreferenceOptions(db);
249
- debug('running dbStats for `%s`...', name);
250
- client.db(name).command(spec, options, function (err, res) {
251
- if (err || !res) {
252
- debug('dbStats failed. Falling back to no stats.');
253
- res = {};
254
- }
255
- else {
256
- debug('got dbStats for `%s`', name, res);
257
- }
258
- const dbName = res.db || name;
259
- const details = {
260
- _id: dbName,
261
- name: dbName,
262
- document_count: res.objects || 0,
263
- storage_size: res.storageSize || 0,
264
- index_count: res.indexes || 0,
265
- index_size: res.indexSize || 0,
266
- };
267
- done === null || done === void 0 ? void 0 : done(null, details);
268
- });
269
- }
270
- function getDatabases(results, done) {
271
- const db = results.db;
272
- const client = results.client;
273
- const dbnames = lodash_1.union(results.listDatabases, results.allowedDatabases);
274
- async_1.default.parallel(dbnames.map((name) => {
275
- return (done) => {
276
- getDatabase(client, db, name, done);
277
- };
278
- }), done);
95
+ return result;
279
96
  }
280
- function getUserInfo(results, done) {
281
- const db = results.db;
282
- const options = getReadPreferenceOptions(db);
283
- db.command({
284
- connectionStatus: 1,
285
- showPrivileges: true,
286
- }, options, function (err, res) {
287
- if (err) {
288
- return done(err);
289
- }
290
- if (!lodash_1.has(res, 'authInfo.authenticatedUsers') ||
291
- !res.authInfo.authenticatedUsers[0]) {
292
- debug('no logged in user, returning empty document');
293
- return done(null, {});
294
- }
295
- const user = res.authInfo.authenticatedUsers[0];
296
- db.command({ usersInfo: user, showPrivileges: true }, options, function (_err, _res) {
297
- if (_err) {
298
- debug(`Command "usersInfo" could not be retrieved: ${(_err === null || _err === void 0 ? void 0 : _err.message) || '<no result>'}`);
299
- return done(null, {});
300
- }
301
- done(null, _res.users[0] || {});
302
- });
303
- });
304
- }
305
- function getAllowedDatabases(results, done) {
306
- const userInfo = results.userInfo;
307
- let databases = security
308
- .getResourcesWithActions(userInfo, ['listCollections'])
309
- .map(function (resource) {
310
- return resource.db;
311
- });
312
- databases = databases.concat(security
313
- .getResourcesWithActions(userInfo, ['find'])
314
- .map(function (resource) {
315
- return resource.db;
316
- }));
317
- done(null, databases.filter((f, i) => f && databases.indexOf(f) === i));
318
- }
319
- exports.getAllowedDatabases = getAllowedDatabases;
320
- function parseCollection(resp) {
321
- const ns = toNS(`${resp.db}.${resp.name}`);
322
- return {
323
- _id: ns.toString(),
324
- name: ns.collection,
325
- database: ns.database,
326
- readonly: lodash_1.get(resp, 'info.readOnly', false),
327
- collation: lodash_1.get(resp, 'options.collation', null),
328
- type: lodash_1.get(resp, 'type', 'collection'),
329
- view_on: lodash_1.get(resp, 'options.viewOn', undefined),
330
- pipeline: lodash_1.get(resp, 'options.pipeline', undefined),
331
- };
332
- }
333
- function getAllowedCollections(results, done) {
334
- const userInfo = results.userInfo;
335
- const compassActions = ['find', 'collStats'];
336
- let collections = security
337
- .getResourcesWithActions(userInfo, compassActions)
338
- .map(function (resource) {
339
- return {
340
- db: resource.db,
341
- name: resource.collection,
342
- };
343
- });
344
- collections = collections
345
- .concat(security
346
- .getResourcesWithActions(userInfo, ['find'])
347
- .map(function (resource) {
348
- return {
349
- db: resource.db,
350
- name: resource.collection,
351
- };
352
- }))
353
- .filter((f) => f.name);
354
- collections = lodash_1.uniqBy(collections, (c) => `${c.db}.${c.name}`);
355
- const collDetails = lodash_1.map(collections, parseCollection);
356
- debug('allowed collections', collDetails);
357
- done(null, collDetails);
358
- }
359
- exports.getAllowedCollections = getAllowedCollections;
360
- function isMongosLocalException(err) {
97
+ exports.getPrivilegesByDatabaseAndCollection = getPrivilegesByDatabaseAndCollection;
98
+ function isNotAuthorized(err) {
361
99
  if (!err) {
362
100
  return false;
363
101
  }
364
- const msg = err.message || err.err || JSON.stringify(err);
365
- return new RegExp('database through mongos').test(msg);
366
- }
367
- function getDatabaseCollections(db, done) {
368
- debug('getDatabaseCollections...');
369
- const spec = {};
370
- db.listCollections(spec, getReadPreferenceOptions(db)).toArray(function (err, res) {
371
- if (err) {
372
- if (isNotAuthorized(err) || isMongosLocalException(err)) {
373
- debug('not allowed to run `listCollections` command on %s, returning' +
374
- ' empty result [].', db.databaseName);
375
- return done(null, []);
376
- }
377
- debug('listCollections failed', err);
378
- err.command = 'listCollections';
379
- return done(err);
380
- }
381
- done(null, lodash_1.map(res, function (d) {
382
- return parseCollection({
383
- ...d,
384
- db: db.databaseName,
102
+ const msg = err.message || JSON.stringify(err);
103
+ return new RegExp('not (authorized|allowed)').test(msg);
104
+ }
105
+ function ignoreNotAuthorized(fallback) {
106
+ return (err) => {
107
+ if (isNotAuthorized(err)) {
108
+ debug('ignoring not authorized error and returning fallback value:', {
109
+ err,
110
+ fallback,
385
111
  });
386
- }));
387
- });
388
- }
389
- exports.getDatabaseCollections = getDatabaseCollections;
390
- function getCollections(results, done) {
391
- let collections = [
392
- ...results.listCollections,
393
- ...results.allowedCollections,
394
- ].filter((f) => f.name !== '');
395
- collections = lodash_1.uniqBy(collections, (c) => c._id);
396
- done(null, collections);
397
- }
398
- function listCollections(results, done) {
399
- const client = results.client;
400
- const databases = results.databases;
401
- const tasks = databases.map(function (_db) {
402
- return getDatabaseCollections.bind(null, client.db(_db.name));
403
- });
404
- async_1.default.parallel(tasks, function (err, res) {
405
- if (err) {
406
- debug('listCollections failed', err);
407
- return done(err);
112
+ return Promise.resolve(fallback);
408
113
  }
409
- done(null, lodash_1.flatten(res));
410
- });
114
+ return Promise.reject(err);
115
+ };
411
116
  }
412
- exports.listCollections = listCollections;
413
- function getHierarchy(results, done) {
414
- const databases = results.databases;
415
- const collections = lodash_1.groupBy(results.collections, function (collection) {
416
- return collection.database;
417
- });
418
- lodash_1.forEach(databases, function (db) {
419
- db.collections = collections[db.name] || [];
420
- });
421
- done(null);
117
+ function adaptHostInfo(rawHostInfo) {
118
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
119
+ return {
120
+ os: (_a = rawHostInfo.os) === null || _a === void 0 ? void 0 : _a.name,
121
+ os_family: ((_b = rawHostInfo.os) === null || _b === void 0 ? void 0 : _b.type)
122
+ ? rawHostInfo.os.type.toLowerCase()
123
+ : undefined,
124
+ kernel_version: (_c = rawHostInfo.os) === null || _c === void 0 ? void 0 : _c.version,
125
+ kernel_version_string: (_d = rawHostInfo.extra) === null || _d === void 0 ? void 0 : _d.versionString,
126
+ arch: (_e = rawHostInfo.system) === null || _e === void 0 ? void 0 : _e.cpuArch,
127
+ memory_bits: ((_g = (_f = rawHostInfo.system) === null || _f === void 0 ? void 0 : _f.memSizeMB) !== null && _g !== void 0 ? _g : 0) * 1024 * 1024,
128
+ cpu_cores: (_h = rawHostInfo.system) === null || _h === void 0 ? void 0 : _h.numCores,
129
+ cpu_frequency: parseInt(((_j = rawHostInfo.extra) === null || _j === void 0 ? void 0 : _j.cpuFrequencyMHz) || '0', 10) * 1000000,
130
+ };
422
131
  }
423
- function attach(anything, done) {
424
- done(null, anything);
132
+ function adaptBuildInfo(rawBuildInfo) {
133
+ var _a;
134
+ return {
135
+ version: (_a = rawBuildInfo.version) !== null && _a !== void 0 ? _a : '',
136
+ isEnterprise: (0, mongodb_build_info_1.isEnterprise)(rawBuildInfo),
137
+ };
425
138
  }
426
- function getInstanceDetail(client, db, done) {
427
- const tasks = {
428
- client: attach.bind(null, client),
429
- db: attach.bind(null, db),
430
- userInfo: ['client', 'db', getUserInfo],
431
- host: ['client', 'db', getHostInfo],
432
- build: ['client', 'db', getBuildInfo],
433
- featureCompatibilityVersion: [
434
- 'client',
435
- 'db',
436
- getFeatureCompatibilityVersion,
437
- ],
438
- cmdLineOpts: ['client', 'db', getCmdLineOpts],
439
- genuineMongoDB: ['build', 'cmdLineOpts', getGenuineMongoDB],
440
- dataLake: ['build', getDataLake],
441
- listDatabases: ['client', 'db', 'userInfo', listDatabases],
442
- allowedDatabases: ['userInfo', getAllowedDatabases],
443
- databases: [
444
- 'client',
445
- 'db',
446
- 'listDatabases',
447
- 'allowedDatabases',
448
- getDatabases,
449
- ],
450
- listCollections: ['client', 'db', 'databases', listCollections],
451
- allowedCollections: ['userInfo', getAllowedCollections],
452
- collections: [
453
- 'client',
454
- 'db',
455
- 'listCollections',
456
- 'allowedCollections',
457
- getCollections,
458
- ],
459
- hierarchy: ['databases', 'collections', getHierarchy],
460
- stats: ['databases', getStats],
139
+ function adaptDatabaseInfo(databaseStats) {
140
+ var _a, _b, _c, _d, _e, _f;
141
+ return {
142
+ collection_count: (_a = databaseStats.collections) !== null && _a !== void 0 ? _a : 0,
143
+ document_count: (_b = databaseStats.objects) !== null && _b !== void 0 ? _b : 0,
144
+ index_count: (_c = databaseStats.indexes) !== null && _c !== void 0 ? _c : 0,
145
+ storage_size: (_d = databaseStats.storageSize) !== null && _d !== void 0 ? _d : 0,
146
+ data_size: (_e = databaseStats.dataSize) !== null && _e !== void 0 ? _e : 0,
147
+ index_size: (_f = databaseStats.indexSize) !== null && _f !== void 0 ? _f : 0,
461
148
  };
462
- async_1.default.auto(tasks, function (err, results) {
463
- if (err) {
464
- return done(err);
465
- }
466
- const cleanedResult = lodash_1.omit(results, [
467
- 'db',
468
- 'listDatabases',
469
- 'allowedDatabases',
470
- 'userInfo',
471
- 'listCollections',
472
- 'allowedCollections',
473
- 'cmdLineOpts',
474
- ]);
475
- return done(null, cleanedResult);
476
- });
477
149
  }
478
- function getInstance(client, db, done) {
479
- getInstanceDetail(client, db, function (err, res) {
480
- if (err) {
481
- return done(err);
482
- }
483
- debug('instance.get returning', res);
484
- done(null, res);
485
- });
150
+ exports.adaptDatabaseInfo = adaptDatabaseInfo;
151
+ function adaptCollectionInfo({ db, name, info, options, type, }) {
152
+ const ns = (0, mongodb_ns_1.default)(`${db}.${name}`);
153
+ const { collection, database, system, oplog, command, special, specialish, normal, } = ns;
154
+ const { readOnly } = info !== null && info !== void 0 ? info : {};
155
+ const { collation, viewOn, pipeline, validator, validationAction, validationLevel, } = options !== null && options !== void 0 ? options : {};
156
+ const hasValidation = Boolean(validator || validationAction || validationLevel);
157
+ return {
158
+ _id: ns.toString(),
159
+ name: collection,
160
+ database,
161
+ system,
162
+ oplog,
163
+ command,
164
+ special,
165
+ specialish,
166
+ normal,
167
+ type: type !== null && type !== void 0 ? type : 'collection',
168
+ readonly: readOnly !== null && readOnly !== void 0 ? readOnly : false,
169
+ collation: collation !== null && collation !== void 0 ? collation : null,
170
+ view_on: viewOn !== null && viewOn !== void 0 ? viewOn : null,
171
+ pipeline: pipeline !== null && pipeline !== void 0 ? pipeline : null,
172
+ validation: hasValidation
173
+ ? { validator, validationAction, validationLevel }
174
+ : null,
175
+ };
486
176
  }
487
- exports.getInstance = getInstance;
177
+ exports.adaptCollectionInfo = adaptCollectionInfo;
488
178
  //# sourceMappingURL=instance-detail-helper.js.map