Skip to content

Commit 7c9d112

Browse files
committed
Ran reformat
1 parent 0dbbb9c commit 7c9d112

File tree

4 files changed

+268
-255
lines changed

4 files changed

+268
-255
lines changed

packages/mongodb-build-info/README.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,87 @@ Helpful functions to figure out if a connection is on Atlas, Atlas Data Lake,
44
Enterpise, or DocumentDB/CosmosDB.
55

66
# Usage
7+
78
```js
8-
const getBuildInfo = require('mongodb-build-info')
9-
const MongoClient = require('mongodb').MongoClient
9+
const getBuildInfo = require('mongodb-build-info');
10+
const MongoClient = require('mongodb').MongoClient;
1011

1112
MongoClient.connect('localhost:27017', function (err, client) {
12-
const adminDB = client.db('test').admin()
13+
const adminDB = client.db('test').admin();
1314
let buildInfo;
1415

15-
adminDB.command({ buildInfo: 1 }, {}, parseBuildInfo)
16-
adminDB.command({ getCmdLineOpts: 1 }, {}, parseCmdLineOpts)
16+
adminDB.command({ buildInfo: 1 }, {}, parseBuildInfo);
17+
adminDB.command({ getCmdLineOpts: 1 }, {}, parseCmdLineOpts);
1718

18-
function parseBuildInfo (err, res) {
19-
if (err) console.log('Command failed, ', err)
20-
buildInfo = res
19+
function parseBuildInfo(err, res) {
20+
if (err) console.log('Command failed, ', err);
21+
buildInfo = res;
2122

22-
const { isDataLake, dlVersion } = getBuildInfo.getDataLake(buildInfo)
23-
const isEnterprise = getBuildInfo.isEnterprise(buildInfo)
23+
const { isDataLake, dlVersion } = getBuildInfo.getDataLake(buildInfo);
24+
const isEnterprise = getBuildInfo.isEnterprise(buildInfo);
2425
}
2526

26-
function parseCmdLineOpts (err, res) {
27-
if (err) console.log('Command failed', err.message)
27+
function parseCmdLineOpts(err, res) {
28+
if (err) console.log('Command failed', err.message);
2829

29-
const { isGenuine, serverName } = getGenuineMongoDB(buildInfo, res)
30+
const { isGenuine, serverName } = getGenuineMongoDB(buildInfo, res);
3031
}
31-
})
32+
});
3233
```
3334

3435
## API
36+
3537
### getDataLake(buildInfo)
38+
3639
Returns an object:
3740

38-
__isDataLake__: boolean.
39-
__dlVersion__: version of dataLake, a string.
41+
**isDataLake**: boolean.
42+
**dlVersion**: version of dataLake, a string.
4043

4144
### isEnterprise(buildInfo)
45+
4246
Returns a boolean.
4347

4448
### isAtlas(uri)
49+
4550
Returns a boolean.
4651

4752
### isLocalAtlas(count: (db: string, coll: string, query: Document) => Promise\<number\>)
53+
4854
Returns a Promise\<boolean\>.
4955

5056
### isAtlasStream(uri)
57+
5158
Returns a boolean.
5259

5360
### isLocalhost(uri)
61+
5462
Returns a boolean.
5563

5664
### isDigitalOcean(uri)
65+
5766
Returns a boolean.
5867

5968
### getGenuineMongoDB(buildInfo, cmdLineOpts)
69+
6070
Returns an object:
6171

62-
__isGenuine__: boolean.
63-
__serverName__: name of the server (mongoDB, cosmosDB, or documentDB).
72+
**isGenuine**: boolean.
73+
**serverName**: name of the server (mongoDB, cosmosDB, or documentDB).
6474

6575
### getBuildEnv(buildInfo)
76+
6677
Returns an object:
6778

68-
__serverOs__: build's OS version (macOS, linux, windows etc.).
69-
__serverArch__: build's architecture (e.g. x86_64).
79+
**serverOs**: build's OS version (macOS, linux, windows etc.).
80+
**serverArch**: build's architecture (e.g. x86_64).
7081

7182
# Installation
83+
7284
```
7385
npm install -S mongodb-build-info
7486
```
7587

7688
# License
89+
7790
Apache-2.0

packages/mongodb-build-info/src/index.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ConnectionString from "mongodb-connection-string-url";
1+
import ConnectionString from 'mongodb-connection-string-url';
22

33
const ATLAS_REGEX = /\.mongodb(-dev|-qa|-stage)?\.net$/i;
44
const ATLAS_STREAM_REGEX = /^atlas-stream-.+/i;
@@ -9,7 +9,7 @@ const COSMOS_DB_REGEX = /\.cosmos\.azure\.com$/i;
99
const DOCUMENT_DB_REGEX = /docdb(-elastic)?\.amazonaws\.com$/i;
1010

1111
function isRecord(value: unknown): value is Record<string, unknown> {
12-
return typeof value === "object" && value !== null;
12+
return typeof value === 'object' && value !== null;
1313
}
1414

1515
export function getDataLake(buildInfo: unknown): {
@@ -19,7 +19,7 @@ export function getDataLake(buildInfo: unknown): {
1919
if (
2020
isRecord(buildInfo) &&
2121
isRecord(buildInfo.dataLake) &&
22-
typeof buildInfo.dataLake.version === "string"
22+
typeof buildInfo.dataLake.version === 'string'
2323
) {
2424
return {
2525
isDataLake: true,
@@ -39,15 +39,15 @@ export function isEnterprise(buildInfo: unknown): boolean {
3939
}
4040

4141
if (
42-
typeof buildInfo.gitVersion === "string" &&
42+
typeof buildInfo.gitVersion === 'string' &&
4343
buildInfo.gitVersion.match(/enterprise/)
4444
) {
4545
return true;
4646
}
4747

4848
if (
4949
Array.isArray(buildInfo.modules) &&
50-
buildInfo.modules.indexOf("enterprise") !== -1
50+
buildInfo.modules.indexOf('enterprise') !== -1
5151
) {
5252
return true;
5353
}
@@ -56,16 +56,16 @@ export function isEnterprise(buildInfo: unknown): boolean {
5656
}
5757

5858
function getHostnameFromHost(host: string): string {
59-
if (host.startsWith("[")) {
59+
if (host.startsWith('[')) {
6060
// If it's ipv6 return what's in the brackets.
61-
return host.substring(1).split("]")[0];
61+
return host.substring(1).split(']')[0];
6262
}
63-
return host.split(":")[0];
63+
return host.split(':')[0];
6464
}
6565

6666
function getHostnameFromUrl(url: unknown): string {
67-
if (typeof url !== "string") {
68-
return "";
67+
if (typeof url !== 'string') {
68+
return '';
6969
}
7070

7171
try {
@@ -84,14 +84,14 @@ export function isAtlas(uri: string): boolean {
8484
type IsLocalAtlasCountFn = (
8585
db: string,
8686
ns: string,
87-
query: Record<string, unknown>
87+
query: Record<string, unknown>,
8888
) => Promise<number>;
8989
export async function isLocalAtlas(
90-
countFn: IsLocalAtlasCountFn
90+
countFn: IsLocalAtlasCountFn,
9191
): Promise<boolean> {
9292
try {
93-
const count = await countFn("admin", "atlascli", {
94-
managedClusterType: "atlasCliLocalDevCluster",
93+
const count = await countFn('admin', 'atlascli', {
94+
managedClusterType: 'atlasCliLocalDevCluster',
9595
});
9696
return count > 0;
9797
} catch {
@@ -117,20 +117,20 @@ export function getGenuineMongoDB(uri: string): {
117117
if (hostname.match(COSMOS_DB_REGEX)) {
118118
return {
119119
isGenuine: false,
120-
serverName: "cosmosdb",
120+
serverName: 'cosmosdb',
121121
};
122122
}
123123

124124
if (hostname.match(DOCUMENT_DB_REGEX)) {
125125
return {
126126
isGenuine: false,
127-
serverName: "documentdb",
127+
serverName: 'documentdb',
128128
};
129129
}
130130

131131
return {
132132
isGenuine: true,
133-
serverName: "mongodb",
133+
serverName: 'mongodb',
134134
};
135135
}
136136

@@ -146,11 +146,11 @@ export function getBuildEnv(buildInfo: unknown): {
146146

147147
return {
148148
serverOs:
149-
typeof buildEnvironment.target_os === "string"
149+
typeof buildEnvironment.target_os === 'string'
150150
? buildEnvironment.target_os
151151
: null,
152152
serverArch:
153-
typeof buildEnvironment.target_arch === "string"
153+
typeof buildEnvironment.target_arch === 'string'
154154
? buildEnvironment.target_arch
155155
: null,
156156
};
Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
11
export const BUILD_INFO_OLD = {
2-
version: "2.6.11",
3-
gitVersion: "d00c1735675c457f75a12d530bee85421f0c5548 modules: enterprise",
4-
OpenSSLVersion: "OpenSSL 1.0.1f 6 Jan 2014",
2+
version: '2.6.11',
3+
gitVersion: 'd00c1735675c457f75a12d530bee85421f0c5548 modules: enterprise',
4+
OpenSSLVersion: 'OpenSSL 1.0.1f 6 Jan 2014',
55
sysInfo:
6-
"Linux ip-10-203-203-194 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49",
6+
'Linux ip-10-203-203-194 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49',
77
loaderFlags:
8-
"-fPIC -pthread -Wl,-z,now -rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,-E",
8+
'-fPIC -pthread -Wl,-z,now -rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,-E',
99
compilerFlags:
10-
"-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -pipe -Werror -O3 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -fno-builtin-memcmp",
11-
allocator: "tcmalloc",
10+
'-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -pipe -Werror -O3 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -fno-builtin-memcmp',
11+
allocator: 'tcmalloc',
1212
versionArray: [2, 6, 11, 0],
13-
javascriptEngine: "V8",
13+
javascriptEngine: 'V8',
1414
bits: 64,
1515
debug: false,
1616
maxBsonObjectSize: 16777216,
1717
ok: 1,
1818
};
1919

2020
export const BUILD_INFO_3_2 = {
21-
version: "3.2.0-rc2",
22-
gitVersion: "8a3acb42742182c5e314636041c2df368232bbc5",
23-
modules: ["enterprise"],
24-
allocator: "system",
25-
javascriptEngine: "mozjs",
26-
sysInfo: "deprecated",
21+
version: '3.2.0-rc2',
22+
gitVersion: '8a3acb42742182c5e314636041c2df368232bbc5',
23+
modules: ['enterprise'],
24+
allocator: 'system',
25+
javascriptEngine: 'mozjs',
26+
sysInfo: 'deprecated',
2727
versionArray: [3, 2, 0, -48],
2828
openssl: {
29-
running: "OpenSSL 0.9.8zg 14 July 2015",
30-
compiled: "OpenSSL 0.9.8y 5 Feb 2013",
29+
running: 'OpenSSL 0.9.8zg 14 July 2015',
30+
compiled: 'OpenSSL 0.9.8y 5 Feb 2013',
3131
},
3232
buildEnvironment: {
33-
distmod: "",
34-
distarch: "x86_64",
35-
cc: "gcc: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)",
33+
distmod: '',
34+
distarch: 'x86_64',
35+
cc: 'gcc: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
3636
ccflags:
37-
"-fno-omit-frame-pointer -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-unused-const-variable -Wno-missing-braces -mmacosx-version-min=10.7 -fno-builtin-memcmp",
38-
cxx: "g++: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)",
37+
'-fno-omit-frame-pointer -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-unused-const-variable -Wno-missing-braces -mmacosx-version-min=10.7 -fno-builtin-memcmp',
38+
cxx: 'g++: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
3939
cxxflags:
40-
"-Wnon-virtual-dtor -Woverloaded-virtual -stdlib=libc++ -std=c++11",
40+
'-Wnon-virtual-dtor -Woverloaded-virtual -stdlib=libc++ -std=c++11',
4141
linkflags:
42-
"-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.7 -stdlib=libc++ -fuse-ld=gold",
43-
target_arch: "x86_64",
44-
target_os: "osx",
42+
'-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.7 -stdlib=libc++ -fuse-ld=gold',
43+
target_arch: 'x86_64',
44+
target_os: 'osx',
4545
},
4646
bits: 64,
4747
debug: false,
4848
maxBsonObjectSize: 16777216,
4949
storageEngines: [
50-
"devnull",
51-
"ephemeralForTest",
52-
"inMemory",
53-
"mmapv1",
54-
"wiredTiger",
50+
'devnull',
51+
'ephemeralForTest',
52+
'inMemory',
53+
'mmapv1',
54+
'wiredTiger',
5555
],
5656
ok: 1,
5757
};
5858

5959
export const CMD_LINE_OPTS = {
6060
argv: [
61-
"/opt/mongodb-osx-x86_64-enterprise-3.6.3/bin/mongod",
62-
"--dbpath=/Users/user/testdata",
61+
'/opt/mongodb-osx-x86_64-enterprise-3.6.3/bin/mongod',
62+
'--dbpath=/Users/user/testdata',
6363
],
6464
parsed: {
6565
storage: {
66-
dbPath: "/Users/user/testdata",
66+
dbPath: '/Users/user/testdata',
6767
},
6868
},
6969
ok: 1,
7070
};
7171

7272
export const COSMOS_DB_URI = [
73-
"mongodb://x:y@compass-serverless.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass-serverless@",
74-
"mongodb://x:y@compass.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass@",
75-
"mongodb+srv://x:y@compass-vcore.mongocluster.cosmos.azure.com/?retrywrites=false&maxIdleTimeMS=120000",
73+
'mongodb://x:y@compass-serverless.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass-serverless@',
74+
'mongodb://x:y@compass.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass@',
75+
'mongodb+srv://x:y@compass-vcore.mongocluster.cosmos.azure.com/?retrywrites=false&maxIdleTimeMS=120000',
7676
];
7777

7878
export const DOCUMENT_DB_URIS = [
79-
"mongodb://x:y@docdb-2001-01-01-01-01-01.cluster-abc.eu-central-1.docdb.amazonaws.com:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false",
80-
"mongodb://x:y@elastic-docdb-123456789.eu-central-1.docdb-elastic.amazonaws.com:27017",
79+
'mongodb://x:y@docdb-2001-01-01-01-01-01.cluster-abc.eu-central-1.docdb.amazonaws.com:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false',
80+
'mongodb://x:y@elastic-docdb-123456789.eu-central-1.docdb-elastic.amazonaws.com:27017',
8181
];
8282

8383
export const COSMOSDB_BUILD_INFO = {
84-
_t: "BuildInfoResponse",
84+
_t: 'BuildInfoResponse',
8585
ok: 1,
86-
version: "3.2.0",
87-
gitVersion: "45d947729a0315accb6d4f15a6b06be6d9c19fe7",
88-
targetMinOS: "Windows 7/Windows Server 2008 R2",
86+
version: '3.2.0',
87+
gitVersion: '45d947729a0315accb6d4f15a6b06be6d9c19fe7',
88+
targetMinOS: 'Windows 7/Windows Server 2008 R2',
8989
modules: [],
90-
allocator: "tcmalloc",
91-
javascriptEngine: "Chakra",
92-
sysInfo: "deprecated",
90+
allocator: 'tcmalloc',
91+
javascriptEngine: 'Chakra',
92+
sysInfo: 'deprecated',
9393
versionArray: [3, 2, 0, 0],
9494
bits: 64,
9595
debug: false,
9696
maxBsonObjectSize: 524288,
9797
openssl: {
98-
running: "OpenSSL 1.0.1p-fips 9 Jul 2015",
99-
compiled: "OpenSSL 1.0.1p-fips 9 Jul 2015",
98+
running: 'OpenSSL 1.0.1p-fips 9 Jul 2015',
99+
compiled: 'OpenSSL 1.0.1p-fips 9 Jul 2015',
100100
},
101101
};
102102

103103
export const DATALAKE_BUILD_INFO = {
104104
ok: 1,
105-
version: "3.6.0",
105+
version: '3.6.0',
106106
versionArray: [3, 6, 0, 0],
107107
dataLake: {
108-
version: "v20200329",
109-
gitVersion: "0f318ss78bfad79ede3721e91iasj6f61644f",
110-
date: "2020-03-29T15:41:22Z",
108+
version: 'v20200329',
109+
gitVersion: '0f318ss78bfad79ede3721e91iasj6f61644f',
110+
date: '2020-03-29T15:41:22Z',
111111
},
112112
};

0 commit comments

Comments
 (0)