@mongosh/service-provider-core 1.10.0 → 1.10.2

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.
@@ -1,84 +1,67 @@
1
- /* eslint camelcase: 0, camelcase: 0 */
2
1
  import { expect } from 'chai';
3
2
  import getConnectInfo from './connect-info';
4
3
 
5
- describe('getConnectInfo', function() {
4
+ describe('getConnectInfo', function () {
6
5
  const BUILD_INFO = {
7
- 'version': '3.2.0-rc2',
8
- 'gitVersion': '8a3acb42742182c5e314636041c2df368232bbc5',
9
- 'modules': [
10
- 'enterprise'
11
- ],
12
- 'allocator': 'system',
13
- 'javascriptEngine': 'mozjs',
14
- 'sysInfo': 'deprecated',
15
- 'versionArray': [
16
- 3,
17
- 2,
18
- 0,
19
- -48
20
- ],
21
- 'openssl': {
22
- 'running': 'OpenSSL 0.9.8zg 14 July 2015',
23
- 'compiled': 'OpenSSL 0.9.8y 5 Feb 2013'
6
+ version: '3.2.0-rc2',
7
+ gitVersion: '8a3acb42742182c5e314636041c2df368232bbc5',
8
+ modules: ['enterprise'],
9
+ allocator: 'system',
10
+ javascriptEngine: 'mozjs',
11
+ sysInfo: 'deprecated',
12
+ versionArray: [3, 2, 0, -48],
13
+ openssl: {
14
+ running: 'OpenSSL 0.9.8zg 14 July 2015',
15
+ compiled: 'OpenSSL 0.9.8y 5 Feb 2013',
24
16
  },
25
- 'buildEnvironment': {
26
- 'distmod': '',
27
- 'distarch': 'x86_64',
28
- 'cc': 'gcc: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
29
- 'ccflags': '-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',
30
- 'cxx': 'g++: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
31
- 'cxxflags': '-Wnon-virtual-dtor -Woverloaded-virtual -stdlib=libc++ -std=c++11',
32
- 'linkflags': '-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.7 -stdlib=libc++ -fuse-ld=gold',
33
- 'target_arch': 'x86_64',
34
- 'target_os': 'osx'
17
+ buildEnvironment: {
18
+ distmod: '',
19
+ distarch: 'x86_64',
20
+ cc: 'gcc: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
21
+ ccflags:
22
+ '-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',
23
+ cxx: 'g++: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)',
24
+ cxxflags:
25
+ '-Wnon-virtual-dtor -Woverloaded-virtual -stdlib=libc++ -std=c++11',
26
+ linkflags:
27
+ '-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.7 -stdlib=libc++ -fuse-ld=gold',
28
+ target_arch: 'x86_64',
29
+ target_os: 'osx',
35
30
  },
36
- 'bits': 64,
37
- 'debug': false,
38
- 'maxBsonObjectSize': 16777216,
39
- 'storageEngines': [
31
+ bits: 64,
32
+ debug: false,
33
+ maxBsonObjectSize: 16777216,
34
+ storageEngines: [
40
35
  'devnull',
41
36
  'ephemeralForTest',
42
37
  'inMemory',
43
38
  'mmapv1',
44
- 'wiredTiger'
39
+ 'wiredTiger',
45
40
  ],
46
- 'ok': 1
47
- };
48
-
49
- const CMD_LINE_OPTS = {
50
- 'argv': [
51
- '/opt/mongodb-osx-x86_64-enterprise-3.6.3/bin/mongod',
52
- '--dbpath=/Users/user/testdata'
53
- ],
54
- 'parsed': {
55
- 'storage': {
56
- 'dbPath': '/Users/user/testdata'
57
- }
58
- },
59
- 'ok': 1
41
+ ok: 1,
60
42
  };
61
43
 
62
44
  const ATLAS_VERSION = {
63
- 'atlasVersion': '20210330.0.0.1617063608',
64
- 'gitVersion': '8f7e5bdde713391e8123a463895bb7fb660a5ffd'
45
+ atlasVersion: '20210330.0.0.1617063608',
46
+ gitVersion: '8f7e5bdde713391e8123a463895bb7fb660a5ffd',
65
47
  };
66
48
 
67
49
  const TOPOLOGY_WITH_CREDENTIALS = {
68
- 's': {
69
- 'credentials': {
70
- 'mechanism': 'LDAP'
71
- }
72
- }
50
+ s: {
51
+ credentials: {
52
+ mechanism: 'LDAP',
53
+ },
54
+ },
73
55
  };
74
56
 
75
57
  const TOPOLOGY_NO_CREDENTIALS = {
76
- 's': {}
58
+ s: {},
77
59
  };
78
60
 
79
- const ATLAS_URI = 'mongodb+srv://admin:catscatscats@cat-data-sets.cats.example.net/admin';
61
+ const ATLAS_URI =
62
+ 'mongodb+srv://admin:catscatscats@cat-data-sets.cats.example.net/admin';
80
63
 
81
- it('reports on an enterprise version >=3.2 of mongodb with credentials', function() {
64
+ it('reports on an enterprise version >=3.2 of mongodb with credentials', function () {
82
65
  const output = {
83
66
  is_atlas: true,
84
67
  is_localhost: false,
@@ -95,18 +78,20 @@ describe('getConnectInfo', function() {
95
78
  server_arch: 'x86_64',
96
79
  node_version: process.version,
97
80
  server_os: 'osx',
98
- uri: ATLAS_URI
81
+ uri: ATLAS_URI,
99
82
  };
100
- expect(getConnectInfo(
101
- ATLAS_URI,
102
- '0.0.6',
103
- BUILD_INFO,
104
- CMD_LINE_OPTS,
105
- ATLAS_VERSION,
106
- TOPOLOGY_WITH_CREDENTIALS)).to.deep.equal(output);
83
+ expect(
84
+ getConnectInfo(
85
+ ATLAS_URI,
86
+ '0.0.6',
87
+ BUILD_INFO,
88
+ ATLAS_VERSION,
89
+ TOPOLOGY_WITH_CREDENTIALS
90
+ )
91
+ ).to.deep.equal(output);
107
92
  });
108
93
 
109
- it('reports on an enterprise version >=3.2 of mongodb with no credentials', function() {
94
+ it('reports on an enterprise version >=3.2 of mongodb with no credentials', function () {
110
95
  const output = {
111
96
  is_atlas: true,
112
97
  is_localhost: false,
@@ -123,18 +108,20 @@ describe('getConnectInfo', function() {
123
108
  server_arch: 'x86_64',
124
109
  node_version: process.version,
125
110
  server_os: 'osx',
126
- uri: ATLAS_URI
111
+ uri: ATLAS_URI,
127
112
  };
128
- expect(getConnectInfo(
129
- ATLAS_URI,
130
- '0.0.6',
131
- BUILD_INFO,
132
- CMD_LINE_OPTS,
133
- ATLAS_VERSION,
134
- TOPOLOGY_NO_CREDENTIALS)).to.deep.equal(output);
113
+ expect(
114
+ getConnectInfo(
115
+ ATLAS_URI,
116
+ '0.0.6',
117
+ BUILD_INFO,
118
+ ATLAS_VERSION,
119
+ TOPOLOGY_NO_CREDENTIALS
120
+ )
121
+ ).to.deep.equal(output);
135
122
  });
136
123
 
137
- it('reports correct information when an empty uri is passed', function() {
124
+ it('reports correct information when an empty uri is passed', function () {
138
125
  const output = {
139
126
  is_atlas: false,
140
127
  is_localhost: false,
@@ -151,18 +138,14 @@ describe('getConnectInfo', function() {
151
138
  server_arch: 'x86_64',
152
139
  node_version: process.version,
153
140
  server_os: 'osx',
154
- uri: ''
141
+ uri: '',
155
142
  };
156
- expect(getConnectInfo(
157
- '',
158
- '0.0.6',
159
- BUILD_INFO,
160
- CMD_LINE_OPTS,
161
- null,
162
- TOPOLOGY_WITH_CREDENTIALS)).to.deep.equal(output);
143
+ expect(
144
+ getConnectInfo('', '0.0.6', BUILD_INFO, null, TOPOLOGY_WITH_CREDENTIALS)
145
+ ).to.deep.equal(output);
163
146
  });
164
147
 
165
- it('does not fail when buildInfo is unavailable', function() {
148
+ it('does not fail when buildInfo is unavailable', function () {
166
149
  const output = {
167
150
  is_atlas: false,
168
151
  is_localhost: false,
@@ -179,14 +162,10 @@ describe('getConnectInfo', function() {
179
162
  server_arch: null,
180
163
  node_version: process.version,
181
164
  server_os: null,
182
- uri: ''
165
+ uri: '',
183
166
  };
184
- expect(getConnectInfo(
185
- '',
186
- '0.0.6',
187
- null,
188
- CMD_LINE_OPTS,
189
- null,
190
- TOPOLOGY_WITH_CREDENTIALS)).to.deep.equal(output);
167
+ expect(
168
+ getConnectInfo('', '0.0.6', null, null, TOPOLOGY_WITH_CREDENTIALS)
169
+ ).to.deep.equal(output);
191
170
  });
192
171
  });
@@ -1,4 +1,3 @@
1
- /* eslint-disable camelcase */
2
1
  // ^ segment data is in snake_case: forgive me javascript, for i have sinned.
3
2
 
4
3
  import getBuildInfo from 'mongodb-build-info';
@@ -22,20 +21,25 @@ export interface ConnectInfo {
22
21
  uri: string;
23
22
  }
24
23
 
25
- export default function getConnectInfo(uri: string, mongoshVersion: string, buildInfo: any, cmdLineOpts: any, atlasVersion: any, topology: any): ConnectInfo {
24
+ export default function getConnectInfo(
25
+ uri: string,
26
+ mongoshVersion: string,
27
+ buildInfo: any,
28
+ atlasVersion: any,
29
+ topology: any
30
+ ): ConnectInfo {
26
31
  buildInfo ??= {}; // We're currently not getting buildInfo with --apiStrict.
27
32
  const { isGenuine: is_genuine, serverName: non_genuine_server_name } =
28
- getBuildInfo.getGenuineMongoDB(buildInfo, cmdLineOpts);
33
+ getBuildInfo.getGenuineMongoDB(uri);
29
34
  // Atlas Data Lake has been renamed to Atlas Data Federation
30
- const { isDataLake: is_data_federation, dlVersion: dl_version }
31
- = getBuildInfo.getDataLake(buildInfo);
35
+ const { isDataLake: is_data_federation, dlVersion: dl_version } =
36
+ getBuildInfo.getDataLake(buildInfo);
32
37
 
33
- // get this information from topology rather than cmdLineOpts, since not all
34
- // connections are able to run getCmdLineOpts command
35
38
  const auth_type = topology.s.credentials
36
- ? topology.s.credentials.mechanism : null;
37
- const { serverOs: server_os, serverArch: server_arch }
38
- = getBuildInfo.getBuildEnv(buildInfo);
39
+ ? topology.s.credentials.mechanism
40
+ : null;
41
+ const { serverOs: server_os, serverArch: server_arch } =
42
+ getBuildInfo.getBuildEnv(buildInfo);
39
43
 
40
44
  return {
41
45
  is_atlas: !!atlasVersion?.atlasVersion || getBuildInfo.isAtlas(uri),
@@ -53,6 +57,6 @@ export default function getConnectInfo(uri: string, mongoshVersion: string, buil
53
57
  dl_version,
54
58
  atlas_version: atlasVersion?.atlasVersion ?? null,
55
59
  is_genuine,
56
- non_genuine_server_name
60
+ non_genuine_server_name,
57
61
  };
58
62
  }
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  calculateObjectSize,
19
19
  Double,
20
20
  EJSON,
21
- BSONRegExp
21
+ BSONRegExp,
22
22
  } from 'bson';
23
23
  import { bsonStringifiers } from './printable-bson';
24
24
  import ShellAuthOptions from './shell-auth-options';
@@ -27,7 +27,10 @@ export * from './all-fle-types';
27
27
 
28
28
  export { MapReduceOptions, FinalizeFunction } from './map-reduce-options';
29
29
 
30
- export { CreateEncryptedCollectionOptions, CheckMetadataConsistencyOptions } from './admin';
30
+ export {
31
+ CreateEncryptedCollectionOptions,
32
+ CheckMetadataConsistencyOptions,
33
+ } from './admin';
31
34
 
32
35
  const bson = {
33
36
  ObjectId,
@@ -44,7 +47,7 @@ const bson = {
44
47
  calculateObjectSize,
45
48
  Double,
46
49
  EJSON,
47
- BSONRegExp
50
+ BSONRegExp,
48
51
  };
49
52
 
50
53
  export {
@@ -56,5 +59,5 @@ export {
56
59
  ServiceProviderCore,
57
60
  bson,
58
61
  bsonStringifiers,
59
- ConnectInfo
62
+ ConnectInfo,
60
63
  };
@@ -1,4 +1,9 @@
1
- import type { CommandOperationOptions, Document, ObjectId, Sort } from 'mongodb';
1
+ import type {
2
+ CommandOperationOptions,
3
+ Document,
4
+ ObjectId,
5
+ Sort,
6
+ } from 'mongodb';
2
7
 
3
8
  export type FinalizeFunction<TKey = ObjectId, TValue = Document> = (
4
9
  key: TKey,
@@ -8,7 +13,12 @@ export type FinalizeFunction<TKey = ObjectId, TValue = Document> = (
8
13
  export interface MapReduceOptions<TKey = ObjectId, TValue = Document>
9
14
  extends CommandOperationOptions {
10
15
  /** Sets the output target for the map reduce job. */
11
- out?: 'inline' | { inline: 1 } | { replace: string } | { merge: string } | { reduce: string };
16
+ out?:
17
+ | 'inline'
18
+ | { inline: 1 }
19
+ | { replace: string }
20
+ | { merge: string }
21
+ | { reduce: string };
12
22
  /** Query filter object. */
13
23
  query?: Document;
14
24
  /** Sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces. */
@@ -3,73 +3,101 @@ import { bson } from './index';
3
3
  import { inspect } from 'util';
4
4
  import makePrintableBson from './printable-bson';
5
5
 
6
- describe('BSON printers', function() {
7
- before('make BSON objects printable', function() {
6
+ describe('BSON printers', function () {
7
+ before('make BSON objects printable', function () {
8
8
  makePrintableBson(bson);
9
9
  });
10
10
 
11
- it('formats ObjectIds correctly', function() {
12
- expect(inspect(new bson.ObjectId('5fa5694f88211043b23c7f11')))
13
- .to.equal('ObjectId("5fa5694f88211043b23c7f11")');
11
+ it('formats ObjectIds correctly', function () {
12
+ expect(inspect(new bson.ObjectId('5fa5694f88211043b23c7f11'))).to.equal(
13
+ 'ObjectId("5fa5694f88211043b23c7f11")'
14
+ );
14
15
  });
15
16
 
16
- it('formats DBRefs correctly', function() {
17
- expect(inspect(new bson.DBRef('a', new bson.ObjectId('5f16b8bebe434dc98cdfc9cb'), 'db')))
18
- .to.equal('DBRef("a", ObjectId("5f16b8bebe434dc98cdfc9cb"), "db")');
19
- expect(inspect(new bson.DBRef('a', 'foo' as any, 'db')))
20
- .to.equal('DBRef("a", \'foo\', "db")');
21
- expect(inspect(new bson.DBRef('a', { x: 1 } as any, 'db')))
22
- .to.equal('DBRef("a", { x: 1 }, "db")');
17
+ it('formats DBRefs correctly', function () {
18
+ expect(
19
+ inspect(
20
+ new bson.DBRef('a', new bson.ObjectId('5f16b8bebe434dc98cdfc9cb'), 'db')
21
+ )
22
+ ).to.equal('DBRef("a", ObjectId("5f16b8bebe434dc98cdfc9cb"), "db")');
23
+ expect(inspect(new bson.DBRef('a', 'foo' as any, 'db'))).to.equal(
24
+ 'DBRef("a", \'foo\', "db")'
25
+ );
26
+ expect(inspect(new bson.DBRef('a', { x: 1 } as any, 'db'))).to.equal(
27
+ 'DBRef("a", { x: 1 }, "db")'
28
+ );
23
29
  });
24
30
 
25
- it('formats MinKey and MaxKey correctly', function() {
31
+ it('formats MinKey and MaxKey correctly', function () {
26
32
  expect(inspect(new bson.MinKey())).to.equal('MinKey()');
27
33
  expect(inspect(new bson.MaxKey())).to.equal('MaxKey()');
28
34
  });
29
35
 
30
- it('formats NumberInt correctly', function() {
36
+ it('formats NumberInt correctly', function () {
31
37
  expect(inspect(new bson.Int32(32))).to.equal('Int32(32)');
32
38
  });
33
39
 
34
- it('formats NumberLong correctly', function() {
40
+ it('formats NumberLong correctly', function () {
35
41
  expect(inspect(bson.Long.fromString('64'))).to.equal('Long("64")');
36
42
  });
37
43
 
38
- it('formats unsigned NumberLong correctly', function() {
39
- expect(inspect(bson.Long.fromString('64', true))).to.equal('Long("64", true)');
44
+ it('formats unsigned NumberLong correctly', function () {
45
+ expect(inspect(bson.Long.fromString('64', true))).to.equal(
46
+ 'Long("64", true)'
47
+ );
40
48
  });
41
49
 
42
- it('formats NumberDecimal correctly', function() {
43
- expect(inspect(bson.Decimal128.fromString('1'))).to.equal('Decimal128("1")');
50
+ it('formats NumberDecimal correctly', function () {
51
+ expect(inspect(bson.Decimal128.fromString('1'))).to.equal(
52
+ 'Decimal128("1")'
53
+ );
44
54
  });
45
55
 
46
- it('formats Timestamp correctly', function() {
47
- expect(inspect(new bson.Timestamp(new bson.Long(100, 1)))).to.equal('Timestamp({ t: 1, i: 100 })');
56
+ it('formats Timestamp correctly', function () {
57
+ expect(inspect(new bson.Timestamp(new bson.Long(100, 1)))).to.equal(
58
+ 'Timestamp({ t: 1, i: 100 })'
59
+ );
48
60
  });
49
61
 
50
- it('formats Symbol correctly', function() {
62
+ it('formats Symbol correctly', function () {
51
63
  expect(inspect(new bson.BSONSymbol('abc'))).to.equal('BSONSymbol("abc")');
52
64
  });
53
65
 
54
- it('formats Code correctly', function() {
66
+ it('formats Code correctly', function () {
55
67
  expect(inspect(new bson.Code('abc'))).to.equal('Code("abc")');
56
68
  });
57
69
 
58
- it('formats BinData correctly', function() {
59
- expect(inspect(new bson.Binary('abc'))).to.equal('Binary(Buffer.from("616263", "hex"), 0)');
70
+ it('formats BinData correctly', function () {
71
+ expect(inspect(new bson.Binary('abc'))).to.equal(
72
+ 'Binary(Buffer.from("616263", "hex"), 0)'
73
+ );
60
74
  });
61
75
 
62
- it('formats BSONRegExp correctly', function() {
63
- expect(inspect(new bson.BSONRegExp('(?-i)AA_', 'im'))).to.equal('BSONRegExp("(?-i)AA_", "im")');
76
+ it('formats BSONRegExp correctly', function () {
77
+ expect(inspect(new bson.BSONRegExp('(?-i)AA_', 'im'))).to.equal(
78
+ 'BSONRegExp("(?-i)AA_", "im")'
79
+ );
64
80
  });
65
81
 
66
- it('formats UUIDs correctly', function() {
67
- expect(inspect(new bson.Binary(Buffer.from('0123456789abcdef0123456789abcdef', 'hex'), 4)))
68
- .to.equal('UUID("01234567-89ab-cdef-0123-456789abcdef")');
82
+ it('formats UUIDs correctly', function () {
83
+ expect(
84
+ inspect(
85
+ new bson.Binary(
86
+ Buffer.from('0123456789abcdef0123456789abcdef', 'hex'),
87
+ 4
88
+ )
89
+ )
90
+ ).to.equal('UUID("01234567-89ab-cdef-0123-456789abcdef")');
69
91
  });
70
92
 
71
- it('formats MD5s correctly', function() {
72
- expect(inspect(new bson.Binary(Buffer.from('0123456789abcdef0123456789abcdef', 'hex'), 5)))
73
- .to.equal('MD5("0123456789abcdef0123456789abcdef")');
93
+ it('formats MD5s correctly', function () {
94
+ expect(
95
+ inspect(
96
+ new bson.Binary(
97
+ Buffer.from('0123456789abcdef0123456789abcdef', 'hex'),
98
+ 5
99
+ )
100
+ )
101
+ ).to.equal('MD5("0123456789abcdef0123456789abcdef")');
74
102
  });
75
103
  });
@@ -2,56 +2,67 @@ import { bson as BSON } from './index';
2
2
  import { inspect } from 'util';
3
3
  const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
4
4
 
5
- export const bsonStringifiers: Record<string, (this: any, depth: any, options: any) => string> = {
6
- ObjectId: function(this: typeof BSON.ObjectId.prototype): string {
5
+ export const bsonStringifiers: Record<
6
+ string,
7
+ (this: any, depth: any, options: any) => string
8
+ > = {
9
+ ObjectId: function (this: typeof BSON.ObjectId.prototype): string {
7
10
  return `ObjectId("${this.toHexString()}")`;
8
11
  },
9
12
 
10
- DBRef: function(this: typeof BSON.DBRef.prototype, depth: any, options: any): string {
11
- return `DBRef("${this.collection}", ` +
13
+ DBRef: function (
14
+ this: typeof BSON.DBRef.prototype,
15
+ depth: any,
16
+ options: any
17
+ ): string {
18
+ return (
19
+ `DBRef("${this.collection}", ` +
12
20
  inspect(this.oid, options) +
13
21
  (this.db ? `, "${this.db}"` : '') +
14
- ')';
22
+ ')'
23
+ );
15
24
  },
16
25
 
17
- MaxKey: function(this: typeof BSON.MaxKey.prototype): string {
26
+ MaxKey: function (this: typeof BSON.MaxKey.prototype): string {
18
27
  return 'MaxKey()';
19
28
  },
20
29
 
21
- MinKey: function(this: typeof BSON.MinKey.prototype): string {
30
+ MinKey: function (this: typeof BSON.MinKey.prototype): string {
22
31
  return 'MinKey()';
23
32
  },
24
33
 
25
- Timestamp: function(this: typeof BSON.Timestamp.prototype): string {
34
+ Timestamp: function (this: typeof BSON.Timestamp.prototype): string {
26
35
  return `Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`;
27
36
  },
28
37
 
29
- BSONSymbol: function(this: typeof BSON.BSONSymbol.prototype): string {
38
+ BSONSymbol: function (this: typeof BSON.BSONSymbol.prototype): string {
30
39
  return `BSONSymbol("${this.valueOf()}")`;
31
40
  },
32
41
 
33
- Code: function(this: typeof BSON.Code.prototype): string {
42
+ Code: function (this: typeof BSON.Code.prototype): string {
34
43
  const j = this.toJSON();
35
44
  return `Code("${j.code}"${j.scope ? `, ${JSON.stringify(j.scope)}` : ''})`;
36
45
  },
37
46
 
38
- Decimal128: function(this: typeof BSON.Decimal128.prototype): string {
47
+ Decimal128: function (this: typeof BSON.Decimal128.prototype): string {
39
48
  return `Decimal128("${this.toString()}")`;
40
49
  },
41
50
 
42
- Int32: function(this: typeof BSON.Int32.prototype): string {
51
+ Int32: function (this: typeof BSON.Int32.prototype): string {
43
52
  return `Int32(${this.valueOf()})`;
44
53
  },
45
54
 
46
- Long: function(this: typeof BSON.Long.prototype): string {
55
+ Long: function (this: typeof BSON.Long.prototype): string {
47
56
  return `Long("${this.toString()}"${this.unsigned ? ', true' : ''})`;
48
57
  },
49
58
 
50
- BSONRegExp: function(this: typeof BSON.BSONRegExp.prototype): string {
51
- return `BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`;
59
+ BSONRegExp: function (this: typeof BSON.BSONRegExp.prototype): string {
60
+ return `BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(
61
+ this.options
62
+ )})`;
52
63
  },
53
64
 
54
- Binary: function(this: typeof BSON.Binary.prototype): string {
65
+ Binary: function (this: typeof BSON.Binary.prototype): string {
55
66
  const hexString = this.toString('hex');
56
67
  switch (this.sub_type) {
57
68
  case BSON.Binary.SUBTYPE_MD5:
@@ -60,12 +71,14 @@ export const bsonStringifiers: Record<string, (this: any, depth: any, options: a
60
71
  if (hexString.length === 32) {
61
72
  // Format '0123456789abcdef0123456789abcdef' into
62
73
  // '01234567-89ab-cdef-0123-456789abcdef'.
63
- const asUUID = hexString.match(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/)!
64
- .slice(1, 6).join('-');
74
+ const asUUID = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/
75
+ .exec(hexString)!
76
+ .slice(1, 6)
77
+ .join('-');
65
78
  return `UUID("${asUUID}")`;
66
79
  }
67
- // In case somebody did something weird and used an UUID with a
68
- // non-standard length, fall through.
80
+ // In case somebody did something weird and used an UUID with a
81
+ // non-standard length, fall through.
69
82
  default:
70
83
  return `Binary(Buffer.from("${hexString}", "hex"), ${this.sub_type})`;
71
84
  }
@@ -78,12 +91,12 @@ bsonStringifiers.ObjectID = bsonStringifiers.ObjectId;
78
91
  * we can have the driver return our BSON classes without having to write our own serializer.
79
92
  * @param {Object} bson
80
93
  */
81
- export default function(bson?: typeof BSON): void {
94
+ export default function (bson?: typeof BSON): void {
82
95
  if (!bson) {
83
96
  bson = BSON;
84
97
  }
85
98
 
86
- for (const [ key, stringifier ] of Object.entries(bsonStringifiers)) {
99
+ for (const [key, stringifier] of Object.entries(bsonStringifiers)) {
87
100
  if (!(key in bson)) {
88
101
  continue;
89
102
  }