Skip to content

Commit c8a22e6

Browse files
lint
1 parent 4870a9b commit c8a22e6

8 files changed

Lines changed: 101 additions & 65 deletions

File tree

src/cmap/connection.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export interface ProxyOptions {
119119
/** @public */
120120
export interface ConnectionOptions
121121
extends SupportedNodeConnectionOptions,
122-
StreamDescriptionOptions,
123-
ProxyOptions {
122+
StreamDescriptionOptions,
123+
ProxyOptions {
124124
// Internal creation info
125125
id: number | '<monitor>';
126126
generation: number;
@@ -529,10 +529,10 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
529529
options.documentsReturnedIn == null || !options.raw
530530
? options
531531
: {
532-
...options,
533-
raw: false,
534-
fieldsAsRaw: { [options.documentsReturnedIn]: true }
535-
};
532+
...options,
533+
raw: false,
534+
fieldsAsRaw: { [options.documentsReturnedIn]: true }
535+
};
536536

537537
/** MongoDBResponse instance or subclass */
538538
let document: MongoDBResponse | undefined = undefined;
@@ -695,9 +695,9 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
695695
options.agreedCompressor === 'none' || !OpCompressedRequest.canCompress(command)
696696
? command
697697
: new OpCompressedRequest(command, {
698-
agreedCompressor: options.agreedCompressor ?? 'none',
699-
zlibCompressionLevel: options.zlibCompressionLevel ?? 0
700-
});
698+
agreedCompressor: options.agreedCompressor ?? 'none',
699+
zlibCompressionLevel: options.zlibCompressionLevel ?? 0
700+
});
701701

702702
const buffer = Buffer.concat(await finalCommand.toBin());
703703

src/mongo_client.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,39 +1035,39 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
10351035
*/
10361036
export interface MongoOptions
10371037
extends Required<
1038-
Pick<
1039-
MongoClientOptions,
1040-
| 'autoEncryption'
1041-
| 'connectTimeoutMS'
1042-
| 'directConnection'
1043-
| 'driverInfo'
1044-
| 'forceServerObjectId'
1045-
| 'minHeartbeatFrequencyMS'
1046-
| 'heartbeatFrequencyMS'
1047-
| 'localThresholdMS'
1048-
| 'maxConnecting'
1049-
| 'maxIdleTimeMS'
1050-
| 'maxPoolSize'
1051-
| 'minPoolSize'
1052-
| 'monitorCommands'
1053-
| 'noDelay'
1054-
| 'pkFactory'
1055-
| 'raw'
1056-
| 'replicaSet'
1057-
| 'retryReads'
1058-
| 'retryWrites'
1059-
| 'serverSelectionTimeoutMS'
1060-
| 'socketTimeoutMS'
1061-
| 'srvMaxHosts'
1062-
| 'srvServiceName'
1063-
| 'tlsAllowInvalidCertificates'
1064-
| 'tlsAllowInvalidHostnames'
1065-
| 'tlsInsecure'
1066-
| 'waitQueueTimeoutMS'
1067-
| 'zlibCompressionLevel'
1068-
>
1069-
>,
1070-
SupportedNodeConnectionOptions {
1038+
Pick<
1039+
MongoClientOptions,
1040+
| 'autoEncryption'
1041+
| 'connectTimeoutMS'
1042+
| 'directConnection'
1043+
| 'driverInfo'
1044+
| 'forceServerObjectId'
1045+
| 'minHeartbeatFrequencyMS'
1046+
| 'heartbeatFrequencyMS'
1047+
| 'localThresholdMS'
1048+
| 'maxConnecting'
1049+
| 'maxIdleTimeMS'
1050+
| 'maxPoolSize'
1051+
| 'minPoolSize'
1052+
| 'monitorCommands'
1053+
| 'noDelay'
1054+
| 'pkFactory'
1055+
| 'raw'
1056+
| 'replicaSet'
1057+
| 'retryReads'
1058+
| 'retryWrites'
1059+
| 'serverSelectionTimeoutMS'
1060+
| 'socketTimeoutMS'
1061+
| 'srvMaxHosts'
1062+
| 'srvServiceName'
1063+
| 'tlsAllowInvalidCertificates'
1064+
| 'tlsAllowInvalidHostnames'
1065+
| 'tlsInsecure'
1066+
| 'waitQueueTimeoutMS'
1067+
| 'zlibCompressionLevel'
1068+
>
1069+
>,
1070+
SupportedNodeConnectionOptions {
10711071
appName?: string;
10721072
hosts: HostAddress[];
10731073
srvHost?: string;

src/runtime_adapters.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @public
3+
* @experimental
4+
*/
5+
export type OsAdapter = Pick<typeof import('os'), 'platform' | 'release' | 'arch' | 'type'>;
6+
7+
/**
8+
* @public
9+
* @experimental
10+
*
11+
* This type represents the interface that the driver needs from the runtime in order to function.
12+
*/
13+
export interface RuntimeAdapters {
14+
os?: OsAdapter;
15+
}
16+
17+
/**
18+
* @internal
19+
*
20+
* Represents a complete, parsed set of runtime adapters. After options parsing, all adapters
21+
* are always present (either using the user's provided adapter, or defaulting to Nodejs' module).
22+
*/
23+
export interface Runtime {
24+
os: OsAdapter;
25+
}

test/tools/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as path from 'node:path';
77
import { EJSON } from 'bson';
88
import * as BSON from 'bson';
99
import { expect } from 'chai';
10+
import * as os from 'os';
1011
import * as process from 'process';
1112
import { Readable } from 'stream';
1213
import { setTimeout } from 'timers';
@@ -18,6 +19,7 @@ import {
1819
type HostAddress,
1920
MongoClient,
2021
type MongoClientOptions,
22+
type Runtime,
2123
type ServerApiVersion,
2224
type TopologyOptions
2325
} from '../../src';
@@ -604,3 +606,7 @@ export function configureMongocryptdSpawnHooks(
604606
port
605607
};
606608
}
609+
610+
export const runtime: Runtime = {
611+
os
612+
};

test/unit/assorted/optional_require.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GSSAPI } from '../../../src/cmap/auth/gssapi';
77
import { compress } from '../../../src/cmap/wire_protocol/compression';
88
import { MongoMissingDependencyError } from '../../../src/error';
99
import { HostAddress } from '../../../src/utils';
10+
import { runtime } from '../../tools/utils';
1011

1112
function moduleExistsSync(moduleName) {
1213
return existsSync(resolve(__dirname, `../../../node_modules/${moduleName}`));
@@ -41,9 +42,13 @@ describe('optionalRequire', function () {
4142
const gssapi = new GSSAPI();
4243

4344
const error = await gssapi
44-
.auth(new AuthContext(null, true, {
45-
hostAddress: new HostAddress('a'), credentials: true, runtime: { os: require('os') }
46-
}))
45+
.auth(
46+
new AuthContext(null, true, {
47+
hostAddress: new HostAddress('a'),
48+
credentials: true,
49+
runtime
50+
})
51+
)
4752
.then(
4853
() => null,
4954
e => e

test/unit/cmap/connect.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { CancellationToken } from '../../../src/mongo_types';
1515
import { HostAddress, isHello } from '../../../src/utils';
1616
import { genClusterTime } from '../../tools/common';
1717
import * as mock from '../../tools/mongodb-mock/index';
18+
import { runtime } from '../../tools/utils';
1819

1920
const CONNECT_DEFAULTS = {
2021
id: 1,
@@ -211,7 +212,7 @@ describe('Connect Tests', function () {
211212
options: {
212213
...CONNECT_DEFAULTS,
213214
metadata: makeClientMetadata([], {
214-
runtime: { os: require('os') }
215+
runtime
215216
})
216217
}
217218
};
@@ -242,7 +243,8 @@ describe('Connect Tests', function () {
242243
}
243244
],
244245
{
245-
appName: longAppName, runtime: { os: require('os') }
246+
appName: longAppName,
247+
runtime
246248
}
247249
);
248250
const longAuthContext = {
@@ -272,7 +274,7 @@ describe('Connect Tests', function () {
272274
options: {
273275
...CONNECT_DEFAULTS,
274276
metadata: makeClientMetadata([], {
275-
runtime: { os: require('os') }
277+
runtime
276278
})
277279
}
278280
};
@@ -304,7 +306,7 @@ describe('Connect Tests', function () {
304306
],
305307
{
306308
appName: longAppName,
307-
runtime: { os: require('os') }
309+
runtime
308310
}
309311
);
310312
const longAuthContext = {

test/unit/cmap/handshake/client_metadata.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import {
1212
makeClientMetadata
1313
} from '../../../../src/cmap/handshake/client_metadata';
1414
import { MongoInvalidArgumentError } from '../../../../src/error';
15-
import { Runtime } from '../../../../src';
16-
17-
const runtime: Runtime = {
18-
os: require('os')
19-
};
2015

2116
describe('client metadata module', () => {
2217
afterEach(() => sinon.restore());
@@ -169,7 +164,9 @@ describe('client metadata module', () => {
169164

170165
context('when driverInfo.platform is provided', () => {
171166
it('throws an error if driverInfo.platform is too large', async () => {
172-
const error = await makeClientMetadata([{ platform: 'a'.repeat(512) }], { runtime }).catch(e => e);
167+
const error = await makeClientMetadata([{ platform: 'a'.repeat(512) }], { runtime }).catch(
168+
e => e
169+
);
173170
expect(error)
174171
.to.be.instanceOf(MongoInvalidArgumentError)
175172
.to.match(/platform/);
@@ -195,7 +192,9 @@ describe('client metadata module', () => {
195192

196193
context('when driverInfo.name is provided', () => {
197194
it('throws an error if driverInfo.name is too large', async () => {
198-
const error = await makeClientMetadata([{ name: 'a'.repeat(512) }], { runtime }).catch(e => e);
195+
const error = await makeClientMetadata([{ name: 'a'.repeat(512) }], { runtime }).catch(
196+
e => e
197+
);
199198
expect(error).to.be.instanceOf(MongoInvalidArgumentError).to.match(/name/);
200199
});
201200

@@ -219,7 +218,9 @@ describe('client metadata module', () => {
219218

220219
context('when driverInfo.version is provided', () => {
221220
it('throws an error if driverInfo.version is too large', async () => {
222-
const error = await makeClientMetadata([{ version: 'a'.repeat(512) }], { runtime }).catch(e => e);
221+
const error = await makeClientMetadata([{ version: 'a'.repeat(512) }], { runtime }).catch(
222+
e => e
223+
);
223224
expect(error)
224225
.to.be.instanceOf(MongoInvalidArgumentError)
225226
.to.match(/version/);
@@ -540,7 +541,9 @@ describe('client metadata module', () => {
540541
});
541542

542543
it('does not attach it to the metadata', async () => {
543-
expect(await makeClientMetadata([], { runtime })).not.to.have.nested.property('aws.memory_mb');
544+
expect(await makeClientMetadata([], { runtime })).not.to.have.nested.property(
545+
'aws.memory_mb'
546+
);
544547
});
545548
});
546549
});

test/unit/sdam/topology.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ import { TopologyDescription } from '../../../src/sdam/topology_description';
2828
import { TimeoutContext } from '../../../src/timeout';
2929
import { isHello, ns } from '../../../src/utils';
3030
import * as mock from '../../tools/mongodb-mock/index';
31-
import { topologyWithPlaceholderClient } from '../../tools/utils';
32-
import { Runtime } from '../../../src';
33-
34-
const runtime: Runtime = {
35-
os: require('os')
36-
};
31+
import { runtime, topologyWithPlaceholderClient } from '../../tools/utils';
3732

3833
describe('Topology (unit)', function () {
3934
let client, topology;
@@ -126,7 +121,7 @@ describe('Topology (unit)', function () {
126121
});
127122
const server = await topology.selectServer('primary', {
128123
timeoutContext: ctx,
129-
operationName: 'none',
124+
operationName: 'none'
130125
});
131126
const err = await server
132127
.command(new RunCursorCommandOperation(ns('admin.$cmd'), { ping: 1 }, {}), ctx)

0 commit comments

Comments
 (0)